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?

Gabriele
  • 1,554
  • 9
  • 21

1 Answers1

10

Use char-after like so:

(eq ?{ (char-after))
phils
  • 50,977
  • 3
  • 79
  • 122
  • Exactly what I needed. – Gabriele Feb 08 '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 08 '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 08 '18 at 22:51
  • Oh, absolutely; my comment was for good style/dwim moreso than warning. – Basil Feb 08 '18 at 22:54
  • 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 08 '18 at 22:59
  • 1
    char-before did what I wanted. – HappyFace May 02 '21 at 13:59