Display vertical line at cursor position on keypress


#1

Are there any packages that would do this? I want to be able to hold a key (alt for instance) and have a vertical line drawn where my cursor is, so I can easily check if I’m indented to the same level as something above. I don’t want to have the indent guides drawn all the time, though if I could toggle them on then off by holding a key then releasing it that would do.


#2

Hi.

I am not following what you are asking.
Untitled

If not this - could you create a picture to show your request?

Regards.
- Dan Padric


#3

It might be possible to use the wrap-guide package as the basis for something like this. I took a look at the code and it doesn’t use any fancy API functions, it just calculates its position based on the character width.


#4


#5

Quick fix hack… not a solution



Hello.

:blush:(…I overlooked the “vertical” - sorry!)

Following through what @DamnedScholar said, I have had a look at your request. I have something that works, but it is a hack. My hack builds (leech) onto the wrap-guide package.

For the hack to work you should not make use of any of the functionality linked to the preferredLineLength configuration linked to page wrapping.

config.cson

editor:
  softWrap: false
  softWrapAtPreferredLineLength: false

:dog:Did I miss something?

Then the hack is as follows: (code seggments follow)

styles.less

atom-text-editor .wrap-guide {
  width: 2px;
  opacity: 0.15;
  background-color: green;
}

keymap.cson

'atom-text-editor:not([mini])':
    '^alt': 'placeRuler' # press & release ALT key

init.coffee

atom.commands.add 'atom-text-editor', 'placeRuler', ->
  return unless _editor = atom.workspace.getActiveTextEditor()
  _position = _editor.getCursorScreenPosition()
  atom.config.set('editor.preferredLineLength', _position.column)

The result in doing this is as follows:
Untitled

By no means perfect!! The line is moved on every editor that is open. BUT is is a place to start if you need something right now. PLUS a toggle action would have been nice.

I hope to see someone take this further.

-Dan Padric


#6

Version 00.00.02…

init.coffee

atom.commands.add 'atom-text-editor', 'placeRuler', ->
  return unless _editor = atom.workspace.getActiveTextEditor()
  if atom.config.get('wrap-guide.enabled')
    atom.config.set('wrap-guide.enabled',false)
  else
    _position = _editor.getCursorScreenPosition()
    atom.config.set('editor.preferredLineLength', _position.column)
    atom.config.set('wrap-guide.enabled',true)

dP


#7

I worked off your v1:

init.coffee:

atom.commands.add 'atom-text-editor', 'placeRuler', ->
  return unless _editor = atom.workspace.getActiveTextEditor()
  _position = _editor.getCursorScreenPosition()
  atom.config.set('editor.preferredLineLength', _position.column)


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

keymap.cson:

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

Thanks!


#8

My v2:

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


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

#9

Hi.

I like your suggestion. Thanks for sharing.

Just a shame that there comes a problem when using alt-tab to go to another window within Windows. I am wondering if there is a method to test for “key up”.

Cheers.


#10

I’m not having any problem with alt-tab. The ^alt triggers on keyup (not on keydown)


#11

Please try:

  1. Open the editor.
  2. Confirm the action:
    a) Place cursor in position
    b) Press in alt - - line appears
    c) Release alt - - line goes away
  3. Leave the cursor in position.
  4. Press alt-tab to select another (not Atom) window.
  5. Press again alt-tab to return to the window with the Atom session in it.
  6. Is the line visible at the cursor?

#12

Discovered an interesting project that would work for @onelivesleft.

Sadly however the project is going to be abandoned
because Atom is working for the developers anymore.

Perhaps someone would like to become the curator. I think this functionality has a place.


#13

Ah, sorry, I thought you meant it was messing up alt-tabbing. Yeah, it leaves the line on the screen; not a big deal, though I had thought about adding a timer. Adding a hook to window-defocus might be better.


#14

Do you know how to? Could you please teach me?


#15

Yeah, this works (in init.coffee):

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

#16

Tested! Very nice
Any hints on what to do if looking at time or key-up?
…I am sort-of looking at this for a project of my own (coffeescript :: Atom).
Just pointing me to what document to reference would already help.

Thanks for the chat and the share!
dP


#17

How about…

atom.getCurrentWindow().on 'click', ->
  atom.config.set('editor.preferredLineLength', 800)
  1. Hold alt down
  2. Click in text somewhere.
  3. Line moves with cursor.

#18

The line moves with the cursor for me without adding that code (I assume because of key repeat) :slight_smile:

I compiled our efforts here:


#19

Thank you very much, useful for me.


#20

I’ve actually been running with slightly different code for a while: autohiding after a second rather than waiting for keyup, because hiding on keyup wasn’t 100% reliable. I’ve updated the gist above; you can choose which mode by setting a variable.