'c' flag in `searchpair()` causes the cursor to jump to the wrong pattern with nested delimiters
Steps to reproduce
Consider this file with LaTeX environment delimiters:
\begin{foo}
bip
\begin{bar}
bop
\end{bar}
bop
\end{foo}
place the cursor on the backslash of \begin{bar} and run :call searchpair('\\begin', '', '\\end', 'cW).
You will see that the cursor jumps to \end{foo}, and \end{bar} is completely ignored.
However, the cursor jumps to the backslash of \end{bar} if one of these conditions applies:
- The function is called when the cursor is placed on the 'b' of
\begin{bar}or any subsequent character; - the function is called as
:call searchpair('\\begin', '', '\\end', 'W'), even when the cursor is placed on the backslash of\begin{bar}.
Expected behaviour
The function should recognise \end{bar} as the delimiter of the pair, and move the cursor to the corresponding backslash.
From my understanding of the documentation, the 'c' flag should prevent the cursor from moving if the text under it matches the desired pattern, but I can't understand why it makes searchpair() completely ignore a valid delimiter.
Version of Vim
9.0.103
Environment
Windows 10 21h2, Gvim 9.0.103
Logs and stack traces
No response