Skip to content

Instantly share code, notes, and snippets.

@jaromero
Created May 23, 2016 04:38
Show Gist options
  • Save jaromero/b49f256521baa56c96d957ff462bfc3a to your computer and use it in GitHub Desktop.
Save jaromero/b49f256521baa56c96d957ff462bfc3a to your computer and use it in GitHub Desktop.
Smart home/end commands for Atom
atom.commands.add 'atom-text-editor',
'user:smart-home': ->
if (editor = atom.workspace.getActiveTextEditor())
bufferPos = editor.getCursorBufferPosition()
screenPos = editor.getCursorScreenPosition()
bufferLine = editor.lineTextForBufferRow bufferPos.row
screenLine = editor.lineTextForScreenRow screenPos.row
screenLineStart = editor.clipScreenPosition [screenPos.row, 0], skipSoftWrapIndentation: true
if bufferLine.startsWith screenLine
editor.moveToFirstCharacterOfLine()
else if screenPos.column isnt screenLineStart.column
editor.moveToFirstCharacterOfLine()
else
editor.moveToBeginningOfLine()
editor.moveToFirstCharacterOfLine()
,
'user:smart-end': ->
if (editor = atom.workspace.getActiveTextEditor())
bufferPos = editor.getCursorBufferPosition()
screenPos = editor.getCursorScreenPosition()
bufferLine = editor.lineTextForBufferRow bufferPos.row
screenLine = editor.lineTextForScreenRow screenPos.row
screenLineEnd = editor.clipScreenPosition [screenPos.row, Infinity], skipSoftWrapIndentation: true
if screenPos.column isnt screenLineEnd.column
editor.moveToEndOfScreenLine()
else
editor.moveToEndOfLine()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment