How to get the current language


#1

How do you get the current language of an editor? For example, I can get all the editors, but I want just the ones with a specific language to tie events to.

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

How would I get the language of this tab?


#2

You can use TextEditor::getGrammar() or TextEditor::observeGrammar(). It returns a Grammar instance.


#3

Thanks, that set me on the right track! For completion’s sake, my final code is this:

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