From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#60856: 29.0.60; C-M-f in python-ts-mode does not work properly with docstrings Date: Mon, 16 Jan 2023 15:18:27 +0100 Message-ID: <87tu0qk1fw.fsf@thornhill.no> References: <87sfgardb4.fsf@galileo.mail-host-address-is-not-set> Reply-To: Theodor Thornhill Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14717"; mail-complaints-to="usenet@ciao.gmane.io" Cc: fgallina@gnu.org, casouri@gmail.com, 60856@debbugs.gnu.org To: Apostolis Bessas Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jan 16 15:19:24 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pHQKY-0003bG-Pq for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 16 Jan 2023 15:19:23 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHQKJ-0006H8-3H; Mon, 16 Jan 2023 09:19:07 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pHQKF-0006G9-6z for bug-gnu-emacs@gnu.org; Mon, 16 Jan 2023 09:19:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pHQKE-0003Zp-Hp for bug-gnu-emacs@gnu.org; Mon, 16 Jan 2023 09:19:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pHQKE-00063I-4U for bug-gnu-emacs@gnu.org; Mon, 16 Jan 2023 09:19:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Theodor Thornhill Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 16 Jan 2023 14:19:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60856 X-GNU-PR-Package: emacs Original-Received: via spool by 60856-submit@debbugs.gnu.org id=B60856.167387871323223 (code B ref 60856); Mon, 16 Jan 2023 14:19:02 +0000 Original-Received: (at 60856) by debbugs.gnu.org; 16 Jan 2023 14:18:33 +0000 Original-Received: from localhost ([127.0.0.1]:60965 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pHQJl-00062V-9j for submit@debbugs.gnu.org; Mon, 16 Jan 2023 09:18:33 -0500 Original-Received: from out-94.mta0.migadu.com ([91.218.175.94]:16653) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pHQJi-00062K-Dn for 60856@debbugs.gnu.org; Mon, 16 Jan 2023 09:18:31 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no; s=key1; t=1673878708; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=kA68I8DHShPKH4t93fdsb3lfPU/RpbWtuPF689iPzjY=; b=H+Y4ks/nF5vR2De/Liyf9+hPcCCdKCLijfVmgPv93tSdg263+yVzZcW3z8buXh1OT1J0JA WfGy+xe+8YwrQ6sf2RwV2wWgJK2VuMriot1X64WYIyHxo92gq+ZqXHLCXBuPI5GL4d2Blg C+sgif7s/6YxGQhV+yt1VlJEzsDgkY89VxvI+zNJV/meEz/18SkW0yC6sEpAniM9WHEIs5 C8mlyPrKh8BYUmF4OhqhoFSWrR7TQgO8fBfaeNNg2eJ03lai1Z06WcDLzdmBvuoSde6JvW tn9LW3QIJCSm30KwAlKUdvQoeHFXkzRpc2NH1ch9iqhqpaHP3u0Q3uQckAZLgQ== In-Reply-To: <87sfgardb4.fsf@galileo.mail-host-address-is-not-set> (Apostolis Bessas's message of "Mon, 16 Jan 2023 12:20:15 +0200") X-Migadu-Flow: FLOW_OUT X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:253495 Archived-At: Hi there! Apostolis Bessas writes: > In python-ts-mode executing C-M-f (forward-sexp) when at the beginning > of a docstring does not go to the end of the docstring (as happens in > python-mode), but at the end of the file. > > However, if I switch to python-mode and then back to python-ts-mode, > C-M-f works correctly. See the following example: > > - Start emacs -Q > - Execute: > > (add-to-list 'auto-mode-alist '("\\.py\\'" . python-ts-mode)) > > - Create the file test.py with the contents: > > """Some docstring. > > The docstring has multiple lines. > """ > > x = 1 > > - Go to the first character in the file (beginning of docstring) and > press C-M-f. The point is moved to the end of the file (after the line > `x = 1`). Instead, the point should have been moved to the end of the > docstring (line 4, last '"' character). > > - Switch to python-mode and then back to python-ts-mode and repeat the > above step. The point is moved to the end of the docstring. > Yeah, I can reproduce this as well. What happens is that python.el redefines and remaps lots of commands, and doesn't set the functions. In addition it uses some internal stuff that if I'm not mistaken isn't really enabled in python-ts-mode. If you try to apply the supplied patch, then execute these steps: 1. M-< ;; go to beginning of buffer 2. M-e 3. M-< 4. M-x forward-sentence You should see the behavior diverges, right? That's because the 'treesit-major-mode-setup' sets up 'forward-sentence-function' which python doesn't set. A fix could be either to set the functions rather than remapping, or make sure we at least create equivalents for python-ts-mode. I think we inherit too much from the python-base-mode, so it is a little hard to reason about where functionalities come from. I added the maintainers of treesit.el and python.el to CC for them to provide some input. Theo diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 21d16db287..973e405e8f 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -6710,6 +6710,10 @@ python-ts-mode "_definition")) (setq-local treesit-defun-name-function #'python--treesit-defun-name) + + (setq-local treesit-sentence-type-regexp + '"statement") + (treesit-major-mode-setup) (when python-indent-guess-indent-offset