Force grammar usage for file extension


I maintain the language-smarty-php package available here:

As you can see in the grammar.cson file, smarty files ends with .tpl or .smarty. But since some times, .tpl files are not associated to the package anymore but with language-html (who define .tpl too).

Is there any way to force .tpl association (letting language-html handling it when when not installed) ?

Or at least is there a way to force association in or config.cson ?



This doesn’t say it can be used for your explicit use-case, but you can give it a shot:

Thanks @dannyfritz but I just tryed and the detected grammar is still language-html

In there is a sample in comments:

atom.workspace.observeTextEditors (editor) ->
  editor.onDidSave ->
    console.log "Saved! #{editor.getPath()}"

Does someone know how to detect the file extension and how to force grammar for the current editor?

Have you tried something along the lines of the code in this post?

You could use the IO.js path module to get the extension and decide whether to change/force the grammar at that point.

1 Like

Thank you @leedohm!

Using this example, I was able to do what I want adding this piece of code to

path = require 'path'

atom.workspace.observeTextEditors (editor) ->
    if path.extname(editor.getPath()) == ".tpl"

This is a good fix for the problem, but maybe it would be usefull to be set natively (selecting grammar for specific file extensions) in Atom.




The request for a feature to override grammars is being tracked here: