Skip to content

Instantly share code, notes, and snippets.

@BenGitsCode
Forked from darklight721/init.coffee
Created February 7, 2017 16:05
Show Gist options
  • Save BenGitsCode/dd4daad9ed8f5ff292244ab182ed0864 to your computer and use it in GitHub Desktop.
Save BenGitsCode/dd4daad9ed8f5ff292244ab182ed0864 to your computer and use it in GitHub Desktop.
An atom command and keymap to quickly end lines with semicolons. Only applies for javascript files. Code is based from turbo-javascript package.
# Open up your atom's init script file and add the following lines, then restart atom.
path = require 'path'
endLine = (insertNewLine) ->
editor = atom.workspace.activePaneItem
if path.extname(editor.getPath()) is '.js'
editor.getCursors().forEach((cursor) ->
editor.moveCursorToEndOfLine()
line = cursor.getCurrentBufferLine().trim()
if line && ';({,=?:'.indexOf(line[line.length - 1]) is -1
editor.insertText(';')
)
if insertNewLine
editor.insertNewlineBelow()
atom.workspaceView.command 'easy-semicolon:end-line', -> endLine(false)
atom.workspaceView.command 'easy-semicolon:end-new-line', -> endLine(true)
# Open up your atom's keymap file and add the following lines.
# This will overwrite the default cmd-enter, but should still work the same for file types other than js.
'.workspace .editor:not(.mini)':
'cmd-enter': 'easy-semicolon:end-new-line'
'cmd-;': 'easy-semicolon:end-line'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment