Subject: bug#59807: closed (Re: bug#59807: 29.0.60; [PATCH] python-ts-mode does not auto-complete the closing quote)

From: [email-masked] (GNU bug Tracking System)
Date: Wed, 14 Dec 2022 02:09:02 +0000

Your bug report

#59807: 29.0.60; [PATCH] python-ts-mode does not auto-complete the closing quote

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
59807: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=59807
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#59807: 29.0.60; [PATCH] python-ts-mode does not auto-complete the closing quote
From: Yuan Fu <[email-masked]>
To: [email-masked]
Cc: Kai Ma <[email-masked]>, [email-masked], Stefan Kangas <[email-masked]>, [email-masked]
Date: Tue, 13 Dec 2022 18:08:27 -0800
List-Id: <debbugs-submit.debbugs.gnu.org>

Yuan Fu <[email-masked]> writes:

>> On Dec 12, 2022, at 6:24 PM, Stefan Kangas <[email-masked]> wrote:
>> 
>> Kai Ma <[email-masked]> writes:
>> 
>>> Unfortunately, I cannot complete the assignment process, at least for
>>> now. The licensing officer at my university is really reluctant to
>>> sign a copyright disclaimer for me.
>> 
>> Thanks for trying.
>
> Yes, thanks!
>
>> 
>>> However, the cumulative number of lines changed by me is below 15 so
>>> far, so at least for this issue, we can move forward. I’ve added
>>> Copyright-paperwork-exempt in the attached patch.
>> 
>> -ENOPATCH
>> 
>
> I can see his patch. I attached it below.

I applied the patch. Due to recent changes on the branch I needed to
modify it a little.  As a result, the patch contains fewer lines of
change.

Yuan

Subject: 29.0.60; [PATCH] python-ts-mode does not auto-complete the closing quote
From: Kai Ma <[email-masked]>
To: [email-masked]
Date: Sun, 04 Dec 2022 06:27:18 +0800
List-Id: <debbugs-submit.debbugs.gnu.org>

When electric-pair-mode is enabled, a single quote ' should be auto
completed to be '' (which means an empty string).  Python-mode correctly
does this, but python-ts-mode does not.  This is clearly a problem
regarding the syntax table.

The attached patch makes python-ts-mode uses the same syntax table as
python-mode's, and fixes this problem.  I also checked a few other ts
modes, and some also have this issue.  For example, js-ts-mode does not
auto complete '' either, which is also fixed by this patch.

>From 7f996826bc47bcdd155eb0cc220a48c32cb2619a Mon Sep 17 00:00:00 2001
From: Kai Ma <[email-masked]>
Date: Sun, 4 Dec 2022 06:15:42 +0800
Subject: [PATCH] Fix syntax tables of tree-sitter modes

Tree-sitter modes should use the same syntax table as the
non-tree-sitter ones.
* lisp/progmodes/csharp-mode.el (csharp-mode-syntax-table)
(csharp-mode):
* lisp/progmodes/js.el (js-mode-syntax-table) (js-ts-mode):
* lisp/progmodes/python.el (python-ts-mode):
* lisp/progmodes/sh-script.el (bash-ts-mode):
* lisp/textmodes/css-mode.el (css-ts-mode):
---
 lisp/progmodes/csharp-mode.el | 3 ++-
 lisp/progmodes/js.el          | 3 ++-
 lisp/progmodes/python.el      | 1 +
 lisp/progmodes/sh-script.el   | 1 +
 lisp/textmodes/css-mode.el    | 1 +
 5 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el
index 3da3079f08..73f2a6ff9e 100644
--- a/lisp/progmodes/csharp-mode.el
+++ b/lisp/progmodes/csharp-mode.el
@@ -608,7 +608,7 @@ csharp-compilation-re-dotnet-testfail
 
 (defvar csharp-mode-syntax-table
   (funcall (c-lang-const c-make-mode-syntax-table csharp))
-  "Syntax table used in `csharp-mode' buffers.")
+  "Syntax table used in `csharp-mode' and `csharp-ts-mode' buffers.")
 
 (defvar csharp-mode-map
   (let ((map (c-make-inherited-keymap)))
@@ -890,6 +890,7 @@ csharp-mode
 ;;;###autoload
 (define-derived-mode csharp-ts-mode prog-mode "C#"
   "Major mode for editing C# code."
+  :syntax-table csharp-mode-syntax-table
 
   (unless (treesit-ready-p 'c-sharp)
     (error "Tree-sitter for C# isn't available"))
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index ad1fe62d42..11e45178f7 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -686,7 +686,7 @@ js-mode-syntax-table
     (modify-syntax-entry ?$ "_" table)
     (modify-syntax-entry ?` "\"" table)
     table)
-  "Syntax table for `js-mode'.")
+  "Syntax table for `js-mode' and `js-ts-mode'.")
 
 (defvar-local js--quick-match-re nil
   "Autogenerated regexp used by `js-mode' to match buffer constructs.")
@@ -3840,6 +3840,7 @@ js-ts-mode
 
 \\<js-ts-mode-map>"
   :group 'js
+  :syntax-table js-mode-syntax-table
   (when (treesit-ready-p 'javascript)
     ;; Borrowed from `js-mode'.
     (setq-local prettify-symbols-alist js--prettify-symbols-alist)
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 4fc5d24e2f..c90124b6b9 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -6618,6 +6618,7 @@ python-ts-mode
   "Major mode for editing Python files, using tree-sitter library.
 
 \\{python-ts-mode-map}"
+  :syntax-table python-mode-syntax-table
   (when (treesit-ready-p 'python)
     (treesit-parser-create 'python)
     (setq-local treesit-font-lock-feature-list
diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el
index e170d18afe..76e8d5b074 100644
--- a/lisp/progmodes/sh-script.el
+++ b/lisp/progmodes/sh-script.el
@@ -1611,6 +1611,7 @@ bash-ts-mode
   "Major mode for editing Bash shell scripts.
 This mode automatically falls back to `sh-mode' if the buffer is
 not written in Bash or sh."
+  :syntax-table sh-mode-syntax-table
   (when (treesit-ready-p 'bash)
     (setq-local treesit-font-lock-feature-list
                 '(( comment function)
diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el
index b82886e397..b3654eaa7f 100644
--- a/lisp/textmodes/css-mode.el
+++ b/lisp/textmodes/css-mode.el
@@ -1822,6 +1822,7 @@ css-ts-mode
 can also be used to fill comments.
 
 \\{css-mode-map}"
+  :syntax-table css-mode-syntax-table
   (when (treesit-ready-p 'css)
     ;; Borrowed from `css-mode'.
     (add-hook 'completion-at-point-functions
-- 
2.37.1 (Apple Git-137.1)

Kai