Subject: Re: bug#60087: 29.0.60; c++-ts-mode conflict with electric-pair-mode

From: Daniel Martín <[email-masked]>
Date: Thu, 15 Dec 2022 13:24:13 +0100

Eason Huang <[email-masked]> writes:

> Hello Emacs dev team,
>
> I found that the c++-ts-mode conflict with electric-pair-mode.
> My build is based on commit a15cd55044c6bb4d4e9f9aec23b8b5b9cbcb38ac
>
> May be the issue was introduced by this commit:
> https://git.savannah.gnu.org/cgit/emacs.git/commit/?h=emacs-29&id=480f41c7deb4d3a45a862a5308950b35085f835d
>
> I can confirm that Before the commit 480f41c7, It work well.
>
> steps to reproduce:
>
> 1. emacs -Q, start Emacs
> 2. C-x, C-f ~/test.cpp, open any cpp file.
> 3. M-x c++-ts-mode, enable c++ tree-sitter support
> 4. M-x electric-pair-mode, enable electric-pair-mode
> 4. Type the following code in the test.cpp buffer.
> ```
> #include <
> ```
> you will the the result as below:
> ```
> #include <<
> ```
>
> expected result is:
> ```
> #include <>
> ```
>

Thanks for the report.  I think the bug is that we need a second
character in the syntax table entry, to set the correct matching
delimiter.

Does the following patch solve this issue and bug#60049?

diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index ff2ff63fd8..11b2b9408c 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -86,8 +86,8 @@ c-ts-mode--syntax-table
 (defvar c++-ts-mode--syntax-table
   (let ((table (make-syntax-table c-ts-mode--syntax-table)))
     ;; Template delimiters.
-    (modify-syntax-entry ?<  "("     table)
-    (modify-syntax-entry ?>  ")"     table)
+    (modify-syntax-entry ?<  "(>"     table)
+    (modify-syntax-entry ?>  ")<"     table)
     table)
   "Syntax table for `c++-ts-mode'.")