5

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

I found:

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

and:

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

both working.

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

Some hint?

1 Answer 1

10

Use char-after like so:

(eq ?{ (char-after))
6
  • Exactly what I needed.
    – Gabriele
    Feb 8, 2018 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, 2018 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, 2018 at 22:51
  • 2
    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, 2018 at 22:59
  • 1
    char-before did what I wanted.
    – HappyFace
    May 2, 2021 at 13:59

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.