1

Is there a build-in variable which saves the current character at which the cursor is positioned on?

1 Answer 1

4

You can use the char-after or following-char function to know what's the character under the cursor (or after the point).

More on Examing Text Under Point

Remember that point is always between characters, and the cursor normally appears over the character following point. 

5
  • Based on your suggestion I wrote a function to determine if the current character is "i" or not but it doesn't work. (defun test-i () (interactive) ;; Check whether the current character is "i" or not. (if (equal (char-after) 'i) (message "yes" )(message "no") ) )
    – Name
    Commented Jan 25, 2015 at 15:09
  • 1
    'i means symbol i. What you need is ?i which returns the decimal ASCII value of the character 'i'. Commented Jan 25, 2015 at 15:26
  • 1
    Here's what I found on learning about elisp symbols from a quick google search: stackoverflow.com/a/1780984/1219634 Commented Jan 25, 2015 at 15:30
  • 1
    On a side note, I prefer using the looking-at function that checks if the current character matches my provided regexp. Here is an example of how I use this function to check if the current character is a space character or a comment-start character: emacs.stackexchange.com/q/7519/115 For you example use case you can do (looking-at "i"). Commented Jan 25, 2015 at 15:47
  • *Correction: looking-at checks regexp match with current character onwards. Commented Jan 25, 2015 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.