Change syntax highlighting based on file extension


#1

I’m wondering if you can take a rabl file and tell atom that all .rabl files should just use ruby syntax highlighting.

Bonus: is there a way to change the language with just the keyboard? Right now I’m clicking at the bottom where it says: “Plain Text”.


#2

You can change the current language with ctrl+shift+l.


#3

Thanks! The keyboard shortcut makes this 100x easier already. I had searched for language and syntax under the keybindings but didn’t think to look for grammar.


#4

Anyone know how to set up a default language for a file extension?

In the settings for languages there is a file types array, any way without packages to set this from Atom?


#5

Full disclosure: I made this package.


#6

Yeah that sounds like it’ll do it. Thanks!!


Cucumber step definition file types
#7

Sorry, I feel your directions are a bit lacking. The ReadMe doesn’t specify how to set an extension to a language.

How would I set the file type of .tgv to “python”.

// THIS CALLS THE FILE-TYPES PACKAGE IN MY .CSON FILE //
‘file-types’:
// WHICH SIDE OF THIS IS THE FILE TYPE AND WHICH SIDE IS THE LANGUAGE TYPE? //
// MY GUESS FOR A PYTHON EXAMPLE WOULD BE ‘Python’: ‘.tgv’ //
// NOT SURE ON THAT THOUGH //
‘ex_em_el’: ‘text.xml’

Thank you for your assistance!


#8

The wording in the read me file is this:

For example, you can associate .ex_em_el with text.xml in your config.cson as follows:

'file-types':
   'ex_em_el': 'text.xml'

Here, text.xml is a scope name. You can find the scope name using the Command Palette and invoking the command “Editor: Log Cursor Scope”. And ex_em_el is the file extension.


#9

You’re a true hero! Thank you very much. So for python the exact code for a ‘tgv’.

‘file-types’:
‘tgv’: ‘source.python’

I hope this, along with kgrossjo’s comment, helps anyone in the future! Thank you!

PS - execjosh, if you put that little tid-bit in your directions, I think it would help silly people, like me. :slight_smile:


#10

I was wrong apparently. It’s not working today. I must have just saved it myself and then not tested it on a different file? I thought I did. Not sure, I’ll report back when I get the answer.


#11

Ok for anyone that comes across this issue of package ‘file-types’ no longer working on version 0.177.0 or above (I’m on Version 0.187.0).

Please see the article Edit/Set File Associations.

It was very helpful. Once you install the package and set your types, simply paste that last comment’s code (code from @Ingram) into your init.coffee and it will let the extension work properly.

I hope this is helpful for anyone that may need this.

PS - I also have the code as ‘.tgv’ and ‘.tsv.tgv’ which is my file type, instead of ‘tgv’ and ‘tsv.tgv’ because that was the example code talked about here. Mine is currently working. Tested on multiple files.


#12

You should make this a PR for the package.


#13

Apologies for reviving this, but first hit on google. I couldn’t get this working with version 0.198.0. Attempted to use extension ui to use source.ruby

Has anyone got this working with the latest version of atom?


#14

I was just able to get this to work. Here is what my config.cson looks like for mapping *.message and *.structure files to protocol buffer.

"file-types": [
    {
      ".message$": "source.protobuf"
      ".structure$": "source.protobuf"
    }
]

#15

For the noobs among us, I didn’t put the code within the * namespace:

"*":
  "file-types":
    'html.ui': "source.ruby"

Putting it within the * seems to fix things.


#16

Looks like this functionality was added in v1.0.8!

Added a setting, core.customFileTypes, for configuring the association between file names and grammars.


How to get certain files to automatically wrap their text?
#17

And to give an example of that format:

    "*":
      core: 
        customFileTypes: {
          "source.json": ["mdastrc"]
        }

Laravel blade template beutify
#18

A post was split to a new topic: Detect and set syntax automatically


#19

This appears to be extremely useful discussion. I would like to assign SPARQL files with files that have *.SPARQL or *.sparql as the extension. I’m using the language-sparql to handle SPARQL language. I was thinking of typying something on the lines:

  "file-types":
    '(sparql|SPARQL)$': 'WhatGoesHere??'

But i’m not sure to which file I should point in case of using the language-sparql extension?


#20
"*":
      core: 
        customFileTypes: {
          "source.rq": ["sparql"]
        }

It does not seem to be case sensitive, but it does not allow regexes, though someone has apparently requested this at https://github.com/atom/atom/issues/9197

FYI, I found the “source.rq” from the scopeName property at the language-sparql repository.