5

How to detect if the point is at a closing delimiter?

For example:

  • in Elisp: )
  • in LaTeX: }
7

This simple code:

(looking-at "\\s)")
  • 1
  • Thanks this works well. When the cursor is at ] in (global-set-key [f7] 'some-command), (looking-at "\\s)") returns nil. Is there an explanation for this? I suspect that here ] is not a closing delimiter, but I am not sure. – Name Sep 2 '15 at 10:08
  • It returns t for me with emacs -Q. Check your config. – abo-abo Sep 2 '15 at 10:21
4

In a syntax table, closing delimiters are denoted by ). You can check the syntax of the character at point with the following predicate function, which will return true if the character is a closing delimiter:

(defun close-delimiter-p ()
  "Is character at point a closing delimiter according to the
syntax table?"
  (eq ?\) (char-syntax (char-after))))
  • Thanks this works well. When the cursor is at ] in (global-set-key [f7] 'some-command), close-delimiter-p returns nil. Is there an explanation for this? I suspect that here ] is not a closing delimiter, but I am not sure. – Name Sep 2 '15 at 10:09

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.