Created
May 23, 2016 04:38
-
-
Save jaromero/b49f256521baa56c96d957ff462bfc3a to your computer and use it in GitHub Desktop.
Smart home/end commands for Atom
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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