Skip to content

Instantly share code, notes, and snippets.

@onelivesleft
Last active May 16, 2018 08:32
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 onelivesleft/881027a8c2252b838005c5245ada6422 to your computer and use it in GitHub Desktop.
Save onelivesleft/881027a8c2252b838005c5245ada6422 to your computer and use it in GitHub Desktop.
Atom hack to show vertical ruler at cursor position on keypress

config.cson:

editor:
  softWrap: false
  softWrapAtPreferredLineLength: false

keymap.cson:

# PC
'atom-text-editor:not([mini])':
  'alt': 'placeRuler'
  '^alt': 'hideRuler'

# Mac
'.platform-darwin atom-text-editor:not([mini])':
  'alt': 'placeRuler'
  '^alt': 'hideRuler'    

init.coffee:

# if RULER_TIMEOUT > 0 then comment out the ^alt keybind in keymap.cson:
#   ruler will disappear after this many seconds
RULER_TIMEOUT = 0

if RULER_TIMEOUT == 0
  atom.commands.add 'atom-text-editor', 'placeRuler': (event) ->
    return unless _editor = atom.workspace.getActiveTextEditor()
    _position = _editor.getCursorScreenPosition()
    atom.config.set('editor.preferredLineLength', _position.column)
else
  RULER_TIMEOUT *= 1000
  atom.commands.add 'atom-text-editor', 'placeRuler': (event) ->
    return unless _editor = atom.workspace.getActiveTextEditor()
    _position = _editor.getCursorScreenPosition()
    atom.config.set('editor.preferredLineLength', _position.column)
    f = () ->
      atom.config.set('editor.preferredLineLength', 800)
    setTimeout f, RULER_TIMEOUT
    event.abortKeyBinding()

atom.commands.add 'atom-text-editor', 'hideRuler': (event) ->
    return unless _editor = atom.workspace.getActiveTextEditor()
    atom.config.set('editor.preferredLineLength', 800)
    event.abortKeyBinding()

atom.getCurrentWindow().on 'blur', ->
    atom.config.set('editor.preferredLineLength', 800)

styles.less:

atom-text-editor .wrap-guide {
    width: 1px;
    opacity: 0.3;
    background-color: #83a598;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment