Is there a build-in variable which saves the current character at which the cursor is positioned on?
Asked
Active
Viewed 275 times
1 Answers
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.

Kaushal Modi
- 25,203
- 3
- 74
- 179
-
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 Jan 25 '15 at 15:09
-
1`'i` means *symbol* i. What you need is `?i` which returns the decimal ASCII value of the character 'i'. – Kaushal Modi Jan 25 '15 at 15:26
-
1Here's what I found on learning about elisp symbols from a quick google search: http://stackoverflow.com/a/1780984/1219634 – Kaushal Modi Jan 25 '15 at 15:30
-
1On 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: http://emacs.stackexchange.com/q/7519/115 For you example use case you can do `(looking-at "i")`. – Kaushal Modi Jan 25 '15 at 15:47
-
*Correction: `looking-at` checks regexp match with current character **onwards**. – Kaushal Modi Jan 25 '15 at 16:26