Skip to content

Instantly share code, notes, and snippets.

@ZachGawlik
Last active September 4, 2017 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZachGawlik/ecf6232be9207b9a5f21478df297d80e to your computer and use it in GitHub Desktop.
Save ZachGawlik/ecf6232be9207b9a5f21478df297d80e to your computer and use it in GitHub Desktop.
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
# console.log "Saved! #{editor.getPath()}"
emptyLine = /^\s*$/
objectLiteralLine = /^\s*[\w'"]+\s*\:\s*/m
continuationLine = /[\{\(;,]\s*$/
# Taken from Turbo Javascript
endLine = (terminator, insertNewLine) ->
editor = atom.workspace.getActiveTextEditor()
editor.getCursors().forEach((cursor) ->
line = cursor.getCurrentBufferLine()
editor.moveToEndOfLine()
if !terminator
# guess the best terminator
terminator = if objectLiteralLine.test(line) then ',' else ';'
editor.insertText(terminator) if !continuationLine.test(line) and !emptyLine.test(line)
editor.insertNewlineBelow() if insertNewLine
)
wrapBlock = () ->
editor = atom.workspace.getActiveTextEditor()
rangesToWrap = editor.getSelectedBufferRanges().filter((r) -> !r.isEmpty())
if rangesToWrap.length
rangesToWrap.sort((a, b) ->
return if a.start.row > b.start.row then -1 else 1
).forEach((range) ->
text = editor.getTextInBufferRange(range)
if (/^\s*\{\s*/.test(text) && /\s*\}\s*/.test(text))
# unwrap each selection from its block
editor.setTextInBufferRange(range, text.replace(/\{\s*/, '').replace(/\s*\}/, ''))
else
# wrap each selection in a block
editor.setTextInBufferRange(range, '{\n' + text + '\n}')
)
editor.autoIndentSelectedRows()
else
# create an empty block at each cursor
editor.insertText('{\n\n}')
editor.selectUp(2)
editor.autoIndentSelectedRows()
editor.moveRight()
editor.moveUp()
editor.moveToEndOfLine()
atom.commands.add 'atom-text-editor',
'turbo-javascript:end-line': => endLine(';', false)
atom.commands.add 'atom-text-editor',
'turbo-javascript:end-line-comma': => endLine(',', false)
atom.commands.add 'atom-text-editor',
'turbo-javascript:end-new-line': => endLine('', true)
atom.commands.add 'atom-text-editor',
'turbo-javascript:wrap-block': => wrapBlock()
# Your keymap
#
# Atom keymaps work similarly to style sheets. Just as style sheets use
# selectors to apply styles to elements, Atom keymaps use selectors to associate
# keystrokes with events in specific contexts. Unlike style sheets however,
# each selector can only be declared once.
#
# You can create a new keybinding in this file by typing 'key' and then hitting
# tab.
#
# Here's an example taken from Atom's built-in keymap:
#
# 'atom-text-editor':
# 'enter': 'editor:newline'
#
# 'atom-workspace':
# 'ctrl-shift-p': 'core:move-up'
# 'ctrl-p': 'core:move-down'
#
# You can find more information about keymaps in these guides:
# * https://atom.io/docs/latest/using-atom-basic-customization#customizing-key-bindings
# * https://atom.io/docs/latest/behind-atom-keymaps-in-depth
#
# If you're having trouble with your keybindings not working, try the
# Keybinding Resolver: `Cmd+.` on OS X and `Ctrl+.` on other platforms. See the
# Debugging Guide for more information:
# * https://atom.io/docs/latest/hacking-atom-debugging#check-the-keybindings
#
# This file uses CoffeeScript Object Notation (CSON).
# If you are unfamiliar with CSON, you can read more about it in the
# Atom Flight Manual:
# https://atom.io/docs/latest/using-atom-basic-customization#cson
# Javascript end line / block
'atom-text-editor':
'ctrl-;': 'turbo-javascript:end-line'
'ctrl-,': 'turbo-javascript:end-line-comma'
'ctrl-enter': 'turbo-javascript:end-new-line'
'ctrl-b': 'turbo-javascript:wrap-block'
'atom-text-editor.vim-mode-plus:not(.insert-mode)':
'k': 'vim-mode-plus:move-up-screen'
'j': 'vim-mode-plus:move-down-screen'
# Stop native ctrl d binding from overriding vim command
'.platform-darwin atom-text-editor:not([mini])':
'ctrl-d': 'vim-mode-plus:scroll-half-screen-down'
[
{
"name": "about",
"version": "1.7.6"
},
{
"name": "advanced-open-file",
"version": "0.16.6"
},
{
"name": "archive-view",
"version": "0.63.3"
},
{
"name": "atom-dark-syntax",
"version": "0.28.0",
"theme": "syntax"
},
{
"name": "atom-dark-ui",
"version": "0.53.0",
"theme": "ui"
},
{
"name": "atom-keyboard-macros",
"version": "0.11.0"
},
{
"name": "atom-keyboard-macros-vim",
"version": "0.1.6"
},
{
"name": "atom-light-syntax",
"version": "0.29.0",
"theme": "syntax"
},
{
"name": "atom-light-ui",
"version": "0.46.0",
"theme": "ui"
},
{
"name": "autocomplete-atom-api",
"version": "0.10.1"
},
{
"name": "autocomplete-css",
"version": "0.16.2"
},
{
"name": "autocomplete-html",
"version": "0.8.0"
},
{
"name": "autocomplete-plus",
"version": "2.35.5"
},
{
"name": "autocomplete-snippets",
"version": "1.11.0"
},
{
"name": "autoflow",
"version": "0.29.0"
},
{
"name": "autosave",
"version": "0.24.3"
},
{
"name": "background-tips",
"version": "0.27.1"
},
{
"name": "base16-tomorrow-dark-theme",
"version": "1.5.0",
"theme": "syntax"
},
{
"name": "base16-tomorrow-light-theme",
"version": "1.5.0",
"theme": "syntax"
},
{
"name": "bookmarks",
"version": "0.44.4"
},
{
"name": "bracket-matcher",
"version": "0.87.3"
},
{
"name": "busy-signal",
"version": "1.4.3"
},
{
"name": "cobalt2-syntax",
"version": "0.5.1",
"theme": "syntax"
},
{
"name": "color-picker",
"version": "2.2.5"
},
{
"name": "command-palette",
"version": "0.40.4"
},
{
"name": "dalek",
"version": "0.2.1"
},
{
"name": "deprecation-cop",
"version": "0.56.7"
},
{
"name": "dev-live-reload",
"version": "0.47.1"
},
{
"name": "editorconfig",
"version": "2.2.2"
},
{
"name": "emmet",
"version": "2.4.3"
},
{
"name": "encoding-selector",
"version": "0.23.4"
},
{
"name": "exception-reporting",
"version": "0.41.4"
},
{
"name": "file-icons",
"version": "2.1.11"
},
{
"name": "find-and-replace",
"version": "0.208.3"
},
{
"name": "flow-ide",
"version": "1.8.1"
},
{
"name": "fuzzy-finder",
"version": "1.5.8"
},
{
"name": "git-blame",
"version": "1.2.2"
},
{
"name": "git-diff",
"version": "1.3.6"
},
{
"name": "github",
"version": "0.3.4-1"
},
{
"name": "go-to-line",
"version": "0.32.1"
},
{
"name": "grammar-selector",
"version": "0.49.5"
},
{
"name": "highlight-selected",
"version": "0.13.1"
},
{
"name": "hyperclick",
"version": "0.1.3"
},
{
"name": "image-view",
"version": "0.61.2"
},
{
"name": "incompatible-packages",
"version": "0.27.3"
},
{
"name": "intentions",
"version": "1.1.5"
},
{
"name": "js-hyperclick",
"version": "1.11.0"
},
{
"name": "keybinding-resolver",
"version": "0.38.0"
},
{
"name": "language-c",
"version": "0.58.1"
},
{
"name": "language-clojure",
"version": "0.22.3"
},
{
"name": "language-coffee-script",
"version": "0.48.7"
},
{
"name": "language-csharp",
"version": "0.14.2"
},
{
"name": "language-css",
"version": "0.42.4"
},
{
"name": "language-gfm",
"version": "0.89.1"
},
{
"name": "language-git",
"version": "0.19.1"
},
{
"name": "language-go",
"version": "0.44.1"
},
{
"name": "language-html",
"version": "0.47.3"
},
{
"name": "language-hyperlink",
"version": "0.16.1"
},
{
"name": "language-java",
"version": "0.27.2"
},
{
"name": "language-javascript",
"version": "0.126.1"
},
{
"name": "language-json",
"version": "0.19.1"
},
{
"name": "language-less",
"version": "0.32.0"
},
{
"name": "language-make",
"version": "0.22.3"
},
{
"name": "language-mustache",
"version": "0.14.1"
},
{
"name": "language-objective-c",
"version": "0.15.1"
},
{
"name": "language-patch",
"version": "1.2.0"
},
{
"name": "language-perl",
"version": "0.37.0"
},
{
"name": "language-php",
"version": "0.39.0"
},
{
"name": "language-property-list",
"version": "0.9.1"
},
{
"name": "language-python",
"version": "0.45.3"
},
{
"name": "language-ruby",
"version": "0.71.1"
},
{
"name": "language-ruby-on-rails",
"version": "0.25.2"
},
{
"name": "language-sass",
"version": "0.59.0"
},
{
"name": "language-shellscript",
"version": "0.25.1"
},
{
"name": "language-source",
"version": "0.9.0"
},
{
"name": "language-sql",
"version": "0.25.6"
},
{
"name": "language-sql-mysql",
"version": "0.3.1"
},
{
"name": "language-text",
"version": "0.7.3"
},
{
"name": "language-todo",
"version": "0.29.1"
},
{
"name": "language-toml",
"version": "0.18.1"
},
{
"name": "language-xml",
"version": "0.35.1"
},
{
"name": "language-yaml",
"version": "0.30.0"
},
{
"name": "line-ending-selector",
"version": "0.7.3"
},
{
"name": "link",
"version": "0.31.3"
},
{
"name": "linter",
"version": "2.2.0"
},
{
"name": "linter-eslint",
"version": "8.2.1"
},
{
"name": "linter-ui-default",
"version": "1.6.7"
},
{
"name": "lorem",
"version": "1.2.1"
},
{
"name": "markdown-preview",
"version": "0.159.12"
},
{
"name": "metrics",
"version": "1.2.6"
},
{
"name": "nice-index",
"version": "1.0.5"
},
{
"name": "notifications",
"version": "0.67.2"
},
{
"name": "one-dark-syntax",
"version": "1.7.1",
"theme": "syntax"
},
{
"name": "one-dark-ui",
"version": "1.10.5",
"theme": "ui"
},
{
"name": "one-light-syntax",
"version": "1.7.1",
"theme": "syntax"
},
{
"name": "one-light-ui",
"version": "1.10.5",
"theme": "ui"
},
{
"name": "open-on-github",
"version": "1.2.1"
},
{
"name": "open-this",
"version": "0.4.0"
},
{
"name": "package-generator",
"version": "1.1.1"
},
{
"name": "pigments",
"version": "0.40.2"
},
{
"name": "prettier-atom",
"version": "0.38.0"
},
{
"name": "react",
"version": "0.16.2"
},
{
"name": "seti-ui",
"version": "1.9.0",
"theme": "ui"
},
{
"name": "settings-view",
"version": "0.250.0"
},
{
"name": "snippets",
"version": "1.1.4"
},
{
"name": "solarized-dark-syntax",
"version": "1.1.2",
"theme": "syntax"
},
{
"name": "solarized-light-syntax",
"version": "1.1.2",
"theme": "syntax"
},
{
"name": "spell-check",
"version": "0.71.4"
},
{
"name": "status-bar",
"version": "1.8.11"
},
{
"name": "styleguide",
"version": "0.49.6"
},
{
"name": "symbols-view",
"version": "0.116.1"
},
{
"name": "sync-settings",
"version": "0.8.2"
},
{
"name": "tabs",
"version": "0.107.0"
},
{
"name": "timecop",
"version": "0.36.0"
},
{
"name": "tree-view",
"version": "0.217.2"
},
{
"name": "update-package-dependencies",
"version": "0.12.0"
},
{
"name": "vim-mode-plus",
"version": "1.0.0"
},
{
"name": "vim-mode-plus-keymaps-for-surround",
"version": "0.2.1"
},
{
"name": "welcome",
"version": "0.36.4"
},
{
"name": "whitespace",
"version": "0.37.2"
},
{
"name": "wrap-guide",
"version": "0.40.2"
}
]
{
"advanced-open-file": {
"createDirectories": true,
"createFileInstantly": true,
"fuzzyMatch": true
},
"atom-beautify": {
"general": {
"_analyticsUserId": "0e2796b9-7762-4ff1-88f2-8d8db9efde29"
}
},
"autocomplete-python": {
"useKite": false
},
"autosave": {
"enabled": true
},
"core": {
"destroyEmptyPanes": false,
"disabledPackages": [
"turbo-javascript"
],
"packagesWithKeymapsDisabled": [],
"telemetryConsent": "no",
"themes": [
"seti-ui",
"cobalt2-syntax"
]
},
"editor": {},
"exception-reporting": {
"userId": "c18dc347-87c1-50a7-771b-a5ca9990897c"
},
"file-icons": {},
"fuzzy-finder": {
"ignoredNames": [
".git",
"node_modules/*"
]
},
"git-blame": {
"columnWidth": 234
},
"linter": {
"lintOnChangeInterval": 1000
},
"linter-eslint": {},
"linter-js-standard": {
"showEslintRules": true,
"style": "semistandard"
},
"linter-ui-default": {
"panelHeight": 56,
"showPanel": true
},
"prettier-atom": {
"formatOnSaveOptions": {
"enabled": true,
"excludedGlobs": [
"*.css",
"*.html"
],
"showInStatusBar": true
},
"prettierOptions": {
"singleQuote": true
},
"silenceErrors": true
},
"seti-ui": {
"compactView": true,
"fileIcons": false,
"font": "Default Atom Font"
},
"sync-settings": {
"analytics": false,
"quietUpdateCheck": true
},
"tree-view": {
"hideIgnoredNames": true,
"hideVcsIgnoredFiles": true
},
"vim-mode-plus": {
"clearHighlightSearchOnResetNormalMode": true,
"clearPersistentSelectionOnResetNormalMode": true,
"highlightSearch": true,
"showHoverSearchCounter": true,
"showHoverSearchCounterDuration": 500,
"useClipboardAsDefaultRegister": true,
"useSmartcaseForSearch": true
},
"welcome": {
"showOnStartup": false
}
}
# Your snippets
#
# Atom snippets allow you to enter a simple prefix in the editor and hit tab to
# expand the prefix into a larger code block with templated values.
#
# You can create a new snippet in this file by typing "snip" and then hitting
# tab.
#
# An example CoffeeScript snippet to expand log to console.log:
#
# '.source.coffee':
# 'Console log':
# 'prefix': 'log'
# 'body': 'console.log '
#
# Each scope (e.g. '.source.coffee' above) can only be declared once.
#
# This file uses CoffeeScript Object Notation (CSON).
# If you are unfamiliar with CSON, you can read more about it in the
# Atom Flight Manual:
# https://atom.io/docs/latest/using-atom-basic-customization#cson
'.source.js':
'console.log':
prefix: 'lg'
body: "console.log(${0});"
'let assignment':
prefix: 'le'
body: "let ${1:name} = ${2:value};"
'const assignment':
prefix: 'co'
body: "const ${1:name} = ${2:value};"
# control flow
'if statement':
prefix: 'if'
body: """
if (${1:condition}) {
${2}
}
"""
'if/else statement':
prefix: 'ife'
body: """
if (${1:condition}) {
${2}
} else {
${3}
}
"""
'else statement':
prefix: 'el'
body: """
else {
${1}
}
"""
'else if statement':
prefix: 'ei'
body: """
else if (${1:condition}) {
${2}
}
"""
# import export
'import module':
prefix: 'im'
body: "import ${1:*} from '${2:module}';"
'import module named':
prefix: 'imn'
body: "import \{ ${1:name} \} from '${2:module}';"
############################
# React
############################
# PropTypes
'React PropType string':
prefix: 'rps',
body: "${1:myProp}: PropTypes.string,"
'React PropType string required':
prefix: 'rpsr',
body: "${1:myProp}: PropTypes.string.isRequired,"
'React PropType number':
prefix: 'rpn',
body: "${1:myProp}: PropTypes.number,"
'React PropType number required':
prefix: 'rpnr',
body: "${1:myProp}: PropTypes.number.isRequired,"
'React PropType object':
prefix: 'rpo',
body: "${1:myProp}: PropTypes.object,"
'React PropType object required':
prefix: 'rpor',
body: "${1:myProp}: PropTypes.object.isRequired,"
'React PropType array':
prefix: 'rpa',
body: "${1:myProp}: PropTypes.array,"
'React PropType array required':
prefix: 'rpar',
body: "${1:myProp}: PropTypes.array.isRequired,"
'React PropType bool':
prefix: 'rpb',
body: "${1:myProp}: PropTypes.bool,"
'React PropType bool required':
prefix: 'rpbr',
body: "${1:myProp}: PropTypes.bool.isRequired,"
'React PropType element':
prefix: 'rpe',
body: "${1:myProp}: PropTypes.element,"
'React PropType element required':
prefix: 'rper',
body: "${1:myProp}: PropTypes.element.isRequired,"
'React PropType function':
prefix: 'rpf',
body: "${1:myProp}: PropTypes.func,"
'React PropType function required':
prefix: 'rpfr',
body: "${1:myProp}: PropTypes.func.isRequired,"
'React PropType shape':
prefix: 'rpsh',
body: """
${1:myProp}: PropTypes.shape({
${2}
}),
"""
'React PropType shape required':
prefix: 'rpshr',
body: """
${1:myProp}: PropTypes.shape({
${2}
}).isRequired,
"""
# Components
'React component':
prefix: 'rc'
body: """
import React from 'react';
import PropTypes from 'prop-types';
class ${1} extends React.Component {
render() {
return (
<div>
${1} Component
</div>
);
}
}
${1}.propTypes = {
${2}
};
export default ${1};
"""
'React: component with constructor':
prefix: 'rcc'
body: """
import React from 'react';
import PropTypes from 'prop-types';
class ${1} extends React.Component {
constructor(props) {
super(props);
this.state = {
};
}
render() {
return (
<div>
${1} Component
</div>
);
}
}
${1}.propTypes = {
${2}
};
export default ${1};
"""
'React stateless component':
prefix: 'rsc'
body: """
import React from 'react';
import PropTypes from 'prop-types';
const ${1} = ({ ${2} }) => (
<div>
${1} Component
</div>
);
${1}.propTypes = {
${3}
};
export default ${1};
"""
############################
# Testing
############################
'describe':
prefix: 'desc'
body: """
describe('${1:description}', () => {
\t${0}
});
"""
'it':
prefix: 'it'
body: """
it('${1:description}', () => {
\t${0}
});
"""
'before':
prefix: 'bef'
body: """
before(() => {
\t${0}
});
"""
'beforeEach':
prefix: 'befe'
body: """
beforeEach(() => {
\t${0}
});
"""
'after':
prefix: 'aft'
body: """
after(() => {
\t${0}
});
"""
'afterEach':
prefix: 'afte'
body: """
afterEach(() => {
\t${0}
});
"""
/*
* Your Stylesheet
*
* This stylesheet is loaded when Atom starts up and is reloaded automatically
* when it is changed and saved.
*
* Add your own CSS or Less to fully customize Atom.
* If you are unfamiliar with Less, you can read more about it here:
* http://lesscss.org
*/
/*
* Examples
* (To see them, uncomment and save)
*/
// style the background color of the tree view
.tree-view {
// background-color: whitesmoke;
}
// style the background and foreground colors on the atom-text-editor-element itself
atom-text-editor {
// color: white;
// background-color: hsl(180, 24%, 12%);
}
// To style other content in the text editor's shadow DOM, use the ::shadow expression
atom-text-editor::shadow .cursor {
// border-color: red;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment