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

白昼怎懂夜的黑 提交于 2019-12-21 07:08:10

问题


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.


回答1:


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.




回答2:


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




回答3:


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.




回答4:


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



来源:https://stackoverflow.com/questions/24653727/github-atom-how-to-apply-a-particular-syntax-highlighting-to-some-files-based-o

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!