Generally forward-sexp
should know what to do in any given mode, so you could perhaps base it on this:
(save-excursion (ignore-errors (forward-sexp) (1- (point))))
Alternatively...
Something like how show-paren-mode
works
You could use that exact same code. Look at M-x find-function
RET show-paren-function
and how it uses the results of (funcall show-paren-data-function)
, and adapt to your purposes.
show-paren-data-function is a variable defined in `paren.el'.
Its value is `show-paren--default'
This variable may be risky if used as a file-local variable.
Documentation:
Function to find the opener/closer "near" point and its match.
The function is called with no argument and should return either nil
if there's no opener/closer near point, or a list of the form
(HERE-BEG HERE-END THERE-BEG THERE-END MISMATCH)
Where HERE-BEG..HERE-END is expected to be near point.