From: Theodor Thornhill via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Apostolis Bessas <apostolis@bessas.me>
Cc: 60856@debbugs.gnu.org
Subject: bug#60856: 29.0.60; C-M-f in python-ts-mode does not work properly with docstrings
Date: Sun, 22 Jan 2023 11:30:17 +0100 [thread overview]
Message-ID: <87ilgy7tfq.fsf@thornhill.no> (raw)
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")
[-- Attachment #1: Type: text/plain, Size: 718 bytes --]
Apostolis Bessas <apostolis@bessas.me> 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
>
Can you test this patch? More nodes are needed, but this is a start, I
think. Must be applied to the master branch :)
Theo
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-sentence-and-sexp-movement-to-python-ts-mode.patch --]
[-- Type: text/x-patch, Size: 1293 bytes --]
From bec1839da51e1fe6c399e636d1cf476fe76682c9 Mon Sep 17 00:00:00 2001
From: Theodor Thornhill <theo@thornhill.no>
Date: Sun, 22 Jan 2023 11:27:37 +0100
Subject: [PATCH] Add sentence and sexp movement to python-ts-mode
* lisp/progmodes/python.el (python-ts-mode): Add relevant node types.
---
lisp/progmodes/python.el | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 21d16db287..2a8fb5fcf5 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -6710,6 +6710,20 @@ python-ts-mode
"_definition"))
(setq-local treesit-defun-name-function
#'python--treesit-defun-name)
+
+ (setq-local treesit-sentence-type-regexp
+ (regexp-opt '("statement"
+ "clause")))
+
+ (setq-local treesit-sexp-type-regexp
+ (regexp-opt '("expression"
+ "string"
+ "call"
+ "operator"
+ "identifier"
+ "integer"
+ "float")))
+
(treesit-major-mode-setup)
(when python-indent-guess-indent-offset
--
2.34.1
next prev parent reply other threads:[~2023-01-22 10:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-16 10:20 bug#60856: 29.0.60; C-M-f in python-ts-mode does not work properly with docstrings Apostolis Bessas
2023-01-16 14:18 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-22 10:30 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-01-22 16:17 ` Apostolis Bessas
2023-09-04 19:51 ` Stefan Kangas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ilgy7tfq.fsf@thornhill.no \
--to=bug-gnu-emacs@gnu.org \
--cc=60856@debbugs.gnu.org \
--cc=apostolis@bessas.me \
--cc=theo@thornhill.no \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).