Default format when opening a new file


#1

Hello,

I’m new to Atom but now I’ve been searching for quite a time for a rather simple feature and it seems it isn’t implemented or I’m to dumb to find it.
How can I set the default format so every time I open a new file it set’s it automatically to my configured format type so I can start coding right away without first needing to specify the format in the down right of the editor?

It seems like a basic feature I can’t find in Atom? Other IDEs all seem to have such a setting, why doesn’t Atom?


#2

If you save a new file, Atom will automatically set the grammar based on the file extension. If you want all new files to have a specific grammar set, you can manage it with an init.coffee tweak that I can show you how to do.


#3

Thanks for your answer. I’d like the format to be automatically set when you open a new file without the need to safe it first. If you know a way I’d be grateful if you tell me.


#4

Put the following in your init.coffee:

atom.workspace.observeTextEditors (editor) ->
  if not editor.getPath()
    editor.setGrammar(atom.grammars.grammarForScopeName("text.html.basic"))

Set language syntax per project or folder? (Atom on Windows)
#5

There’s also a FAQ for this:


#6

Thank you a lot! I hadn’t found the FAQ even though I searched on Google for quite some time for a solution. Now with the code from the FAQ it works perfectly.

Just in case somebody finds this useful:
I wanted to make python the default format and this code in the init.coffee works for me. Make sure to properly indent the lines.

   atom.workspace.observeTextEditors (editor) ->
    original = editor.getGrammar()
    if original? and original is atom.grammars.grammarForScopeName('text.plain.null-grammar')
      editor.setGrammar(atom.grammars.grammarForScopeName('source.python'))