Auto syntax highliting

Hi

I have never used Atom before but it may depend if go into it. I am particularly looking if atom can be configured through plugins or other means to auto-select syntax highlighting based on the very first line of just opened file. I am working with old UNIX style files that is they don’t have extensions in the file name but the extension is defined in the file.

Thanks

There’s a package that detects the syntax from the shebang, if that’s what your after

Hi,

thanks for the reply. I am afraid not, a file type is some number within the first line…

thanks

You can set up a function to run on every file you open, which can read the contents and set the grammar as it likes. Something like as follows (you can replace init.coffee with init.js, or translate this to CoffeeScript)

// ~/.atom/init.js
atom.workspace.observeTextEditors(editor => {
  // read contents with TextEditor API 
  const languageId = "source.gfm"
  atom.grammars.assignLanguageMode(editor, languageId);
})

TextEditor API