I want to test if char at point is, let's say, "{"

I found:

(string= "{" (buffer-substring-no-properties (point) (+ 1 (point))))


(string-match-p "{" (what-cursor-position))

both working.

In the sencond case, it there isn't something better, I'd like to hide the message in the echo area (minibuffer).

Some hint?


Use char-after like so:

(eq ?{ (char-after))
  • Exactly what I needed. Feb 8 '18 at 22:10
  • I think it's usually preferable to use = for character comparison, seeing as the equality of Elisp integers is mostly an implementation detail.
    – Basil
    Feb 8 '18 at 22:19
  • @Basil, I'm pretty sure it's an implementation detail which is never ever going to change, so I don't feel it's a problem, but = is certainly fine as well.
    – phils
    Feb 8 '18 at 22:51
  • Oh, absolutely; my comment was for good style/dwim moreso than warning.
    – Basil
    Feb 8 '18 at 22:54
  • 1
    Sorry, I mistook char-after for the simpler following-char. The former can return nil, in which case eq is needed and = would eventually fail, whereas the latter is guaranteed to return an integer, and so in newer Emacs sources you would usually see (= (following-char) ?{).
    – Basil
    Feb 8 '18 at 22:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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