Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Add CSON primer #100

Merged
merged 6 commits into from
Jul 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions book/02-using-atom/sections/02-text.asc
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ console.log("crash");

The string `"crash"` would be initially selected and pressing tab again would place the cursor after the `;`

WARNING: Snippet keys, unlike CSS selectors, can only be repeated once per level. If there are duplicate keys at the same level, then only the last one will be read. See <<_cson,Configuring with CSON>> for more information.

===== Multi-line Snippet Body

You can also use multi-line syntax using `"""` for larger templates:
Expand Down
49 changes: 49 additions & 0 deletions book/02-using-atom/sections/06-customizing.asc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,55 @@

Now that we are feeling comfortable with just about everything built into Atom, let's look at how to tweak it. Perhaps there is a keybinding that you use a lot but feels wrong or a color that isn't quite right for you. Atom is amazingly flexible, so let's go over some of the simpler flexes it can do.

[[_cson]]
==== Configuring with CSON
All of Atom's config files (with the exception of your <<_style_tweaks, style sheet>> and your <<_the_init_file, Init Script>>) are written in CSON, short for CoffeeScript Object Notation.footnoteref:[cson, https://github.com/bevry/cson#what-is-cson] Just like its namesake JSON (JavaScript Object Notation)footnoteref:[json, http://json.org/], CSON is a text format for storing structured data in the form of simple objects made up of key-value pairs.

----
key:
key: value
key: value
key: [value, value]
----

Objects are the backbone of any CSON file, and are delineated with either indentation (as in the above example), or with curly brackets (`{}`). A key's value can either be a String, a Number, an Object, a Boolean, `null`, or an Array of any of these data types.

WARNING: Unlike CSS's selectors, CSON's keys can only be repeated once per object. If there are duplicate keys, then the last usage of that key overwrites all others, as if they weren't there. The same holds true for Atom's config files.

[WARNING]
====
Avoid this:

[source,coffee]
----
# DON'T DO THIS
'.source.js':
'console.log':
'prefix': 'log'
'body': 'console.log(${1:"crash"});$2'

# Only this snippet will be loaded
'.source.js':
'console.error':
'prefix': 'error'
'body': 'console.error(${1:"crash"});$2'
----

Use this instead:

[source,coffee]
----
# DO THIS: Both of these will be loaded
'.source.js':
'console.log':
'prefix': 'log'
'body': 'console.log(${1:"crash"});$2'
'console.error':
'prefix': 'error'
'body': 'console.error(${1:"crash"});$2'
----
====

[[_style_tweaks]]
==== Style Tweaks

Expand Down