How to check what letter in front of cursor is


#1

Hi,
so I’ve been using this in my init script in order to efficiently tab through specific characters, like ‘)’ and ‘]’, which automatically pop up:
SymbolRegex = /\s*[\ \n(){}<>[\]/'"]/ atom.commands.add 'atom-text-editor', 'custom:jump-over-symbol': (event) -> editor = atom.workspace.getActiveTextEditor() cursorMoved = false for cursor in editor.getCursors() range = cursor.getCurrentWordBufferRange(wordRegex: SymbolRegex) unless range.isEmpty() cursor.setBufferPosition(range.end) cursorMoved = true event.abortKeyBinding() unless cursorMoved

This script uses getCurrentWordBufferRange, which, from what I’ve seen, keeps searching until it finds a word. Would it be possible to instead just check the character directly in front of the cursor and to check if it’s in the regexp? Thanks in advance!


#2

You can use cursor.moveToBeginningOfNextWord(). It’ll skip over any non-word characters. Unless you want to skip to the next non-word character.


#3

I’m trying to only check the character in front of the cursor, and jump over it if it’s in the regexp. Is there any way to only check that one character?


#4

cursor.getBufferPosition(), then editor.getTextInBufferRange()