Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub Atom: How to apply a particular syntax highlighting to some files based on name

How can I configure GitHub's Atom to make it automatically set a particular syntax highlighting to filenames based on name and/or extensions?

Specifically I want it to automatically set Ruby syntax highlightning to Cocoapods' Podfiles.

like image 395
Ricardo Sanchez-Saez Avatar asked Jul 09 '14 12:07

Ricardo Sanchez-Saez


4 Answers

As of Atom 1.0.8 this is now possible without the file-types package, using a core feature. To achieve this, open the config.cson file, and add a section like the following:

"*": # Other config core: customFileTypes: "source.ruby": [ "Podfile" ]

There is guidance on finding the language scope name here: https://flight-manual.atom.io/using-atom/sections/basic-customization/#finding-a-languages-scope-name


This is now possible with the file-types third-party package. I used the following syntax:

"*": # Other config "file-types": "^Podfile$": "source.ruby"

This should be placed in the config.cson file.

Here's an excerpt from the readme:

file-types package

Specify additional file types for languages.

Extension Matchers

Drop the dot before the extension to use extension matchers.

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

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

RegExp Matchers

You can match with regular expressions, too. Most JavaScript regular expressions should work; but, the system looks for a dot (.), a caret (^) at the start, or a dollar ($) to identify RegExp matchers.

For example, you can associate /.*_steps\.rb$/ with source.cucumber.steps in your config.cson as follows:

'file-types': '_steps\\.rb$': 'source.cucumber.steps'

NOTE: Extension Matchers take priority over RegExp Matchers.

like image 89
Maurice Kelly Avatar answered Oct 23 '22 01:10

Maurice Kelly


As of this writing, there is no way to do this short of submitting a PR to the language-ruby package or creating your own fork of the language-ruby package.

There is a bug tracking this issue here: https://github.com/atom/atom/issues/1718

like image 35
Lee Avatar answered Oct 23 '22 01:10

Lee


Anyone arriving here looking to add support for template files in php e.g. .tpl, the folloing works in atom 1.10.2. I do not have previous versions so I can't say about earlier versions.

Add this in your config (config.cson) after core:. I added it after audioBeep: false line.

customFileTypes:
   "text.html.php": [
    "tpl"
   ]

Documentation made me go around in circles. Several articles wrongly mention source.php where as it should be text.html.php

Just getting started with atom coming from npp++ basically as I have struggled with snippet support there and hope atom can do a good job.

like image 4
pipepiper Avatar answered Oct 23 '22 00:10

pipepiper


To add to Maurice Kelly's answer (my reputation is too low to comment) This is now documented at:

https://github.com/atom/flight-manual.atom.io/blob/681c7fe6e69f1f64396ecadfde1323a01e7f5b96/book/02-using-atom/sections/06-customizing.asc

like image 2
Andy Preston Avatar answered Oct 23 '22 00:10

Andy Preston