Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit c657f91

Browse files
committed
📝 Update README.md
1 parent cb07bf0 commit c657f91

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

README.md

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,46 @@ Specify additional file types for languages.
88

99
_Note:_ A subset of this functionality is now available directly in Atom--see [Customizing Language Recognition](http://flight-manual.atom.io/using-atom/sections/basic-customization/#customizing-language-recognition) in the Flight Manual.
1010

11-
## Extension Matchers
11+
# Matchers
1212

13-
To map a filetype to a new language, use the `file-types` option. Specify the extension (without a dot) as a key, and the new default extension as the value.
13+
To map a filetype to a different language, use the `file-types` option in your `config.json` (via the `Atom -> Config...` menu). Specify a pattern to match for the key (in bash-like glob format) and the new scope name for the value.
1414

15-
For example, the `.hbs` extension defaults to the `handlebars` grammar. To change it to default to `html-htmlbars` (installed separately), open your `config.cson` (via the `Atom -> Config...` menu) and add the following rule:
15+
For example, the `.hbs` extension defaults to the `handlebars` grammar. To override this to the `text.html.htmlbars` grammar (provided by the separately installable `html-htmlbars`), add the following rule to your `config.cson`:
1616

1717
```cson
18-
"*": # make sure to put all "file-types" options under the "*" key
18+
"*": # Be sure to put "file-types" under the "*" key
1919
"file-types":
20-
"hbs": "text.html.htmlbars"
20+
"*.hbs": "text.html.htmlbars"
2121
```
2222

23-
An extension matcher will be converted into a RegExp matcher. The example above is equivalent to the following:
23+
## Precedence
2424

25-
```coffee
26-
"*":
27-
"file-types":
28-
"\\.hbs$": "text.html.htmlbars"
29-
```
25+
The longest glob is given precedence.
3026

31-
To see all available grammars registered in your Atom instance, open the Developer Tools Console and execute the following:
27+
For example, with the following settings, all three globs end in `.liquid`.
3228

33-
```javascript
34-
console.log(atom.grammars.getGrammars().map(g => g.scopeName).sort().join('\n'))
29+
```cson
30+
"*":
31+
"file-types":
32+
"*.css.liquid": "source.css"
33+
"*.liquid": "text.html.basic"
34+
"*.scss.liquid": "source.css.scss"
3535
```
3636

37-
## RegExp Matchers
38-
39-
You can match with regular expressions, too. Most JavaScript regular expressions should work; but, the system looks for a dot (`.`), a pipe (`|`), a caret (`^`) at the start, or a dollar (`$`) at the end to identify RegExp matchers.
37+
Both `*.liquid` and `*.css.liquid` would match a file named `super_awesome_file.css.liquid`; however, since `*.css.liquid` is longest, it wins and the `source.css` scope name would be used.
4038

41-
The RegExp is currently matched against the base name of the file, as opposed to the entire path.
39+
This is usually not a problem unless multiple globs of equal length match the filename. When that happens, a warning is displayed and the scope name associated with the "alphabetically last" glob is used.
4240

43-
For example, you can associate `/.*_steps\.rb$/` with `source.cucumber.steps` in your `config.cson` as follows:
41+
Consider the following settings:
4442

4543
```cson
46-
"*": # make sure to put all "file-types" options under the "*" key
44+
"*":
4745
"file-types":
48-
"_steps\\.rb$": "source.cucumber.steps"
46+
"*_spec.rb": "source.ruby.rspec"
47+
"*_sp?c.rb": "text.plain"
4948
```
5049

51-
The longest match is given precedence. If there are multiple matches of equal length, then a warning is displayed and the "last" (alphabetically) match is used.
50+
Both of these would match a file named `super_controller_spec.rb`; however, `*_spec.rb` would win because when sorted alphabetically, it comes last (i.e., `"*_sp?c.rb" < "*_spec.rb"`).
5251

5352
# Scope Names
5453

@@ -57,7 +56,7 @@ The scope name for a grammar can be found in the settings for the corresponding
5756
To get a list of all scope names registered in your Atom instance, open the Developer Tools Console and execute the following:
5857

5958
```javascript
60-
Object.keys(atom.grammars.grammarsByScopeName).sort().join('\n')
59+
console.log(atom.grammars.getGrammars().map(g => g.scopeName).sort().join('\n'))
6160
```
6261

6362
Here is a list of the scope names available by default in Atom v1.8.0:

0 commit comments

Comments
 (0)