Any way to get grammar based on a cursor location?


I am trying to make a package for Atom, and what I am trying to accomplish is to trigger a specific event every time the language changes based on cursor position. Currently I am only able to get the grammar, but this doesn’t change when I am within a different coding language within that same file (ie: javascript within an html file). Here’s how I am doing it currently, any help or answer to this is appreciated -

atom.workspace.observeActiveTextEditor(editor => {
  editor.observeCursors(cursor => {
  cursor.onDidChangePosition(position => {


I don’t think there’s any special events around embedded languages. The actual embedding is not always a new language either; the URL detection and PHP grammars at least use the same injection as any other.

The best I can think of is inspecting the scope list each time. E.g., this is what I see with JS inside HTML


In general, source is used as the root of a language, so it may work to look for that. Some may also start with text though, like text.tex.latex or HTML.


Thanks for the reply.