GNU bug report logs - #77941
[PATCH] Fix Python block end predicates

Previous Next

Package: emacs;

Reported by: kobarity <kobarity <at> gmail.com>

Date: Sun, 20 Apr 2025 14:57:01 UTC

Severity: normal

Tags: patch

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 77941 in the body.
You can then email your comments to 77941 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#77941; Package emacs. (Sun, 20 Apr 2025 14:57:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to kobarity <kobarity <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 20 Apr 2025 14:57:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: kobarity <kobarity <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] Fix Python block end predicates
Date: Sun, 20 Apr 2025 23:56:29 +0900
[Message part 1 (text/plain, inline)]
In the process of looking into #77620, I noticed bugs in the
end-of-block detection functions in python.el.  If there is a comment
on the last line of the block, `python-info-statement-ends-block-p'
and `python-info-end-of-block-p' will not work correctly. 

Try the following Python code.

def func():
    return 0  # Comment

When the point is located after "0" of the return statement, both
`python-info-statement-ends-block-p' and `python-info-end-of-block-p'
return nil.  If there is no comment on the line, they return t as
expected.

This bug affects `python-nav-forward-sexp'.  In the above example, if
the point is located at the beginning of "def func()" line,
(python-nav-forward-sexp) moves the point to after "0".  This is the
expected behavior.

However, if we execute (python-nav-forward-sexp -1) there, it moves
the point to "0". This is not the expected behavior.  If there is no
comment, it moves the point to the beginning of "def func()" line.

Attached is a patch that fixes this problem.

--
In GNU Emacs 31.0.50 (build 8, x86_64-pc-linux-gnu, GTK+ Version
 3.24.41, cairo version 1.18.0) of 2025-01-01 built on ubuntu2404
Repository revision: 78bc5949db489b143f7424540d6cc56fc529c9ea
Repository branch: master
System Description: Ubuntu 24.04.2 LTS

Configured using:
 'configure --with-pgtk --with-native-compilation --with-tree-sitter'
[0001-Fix-Python-block-end-predicates.patch (application/octet-stream, attachment)]

Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Sat, 26 Apr 2025 11:24:02 GMT) Full text and rfc822 format available.

Notification sent to kobarity <kobarity <at> gmail.com>:
bug acknowledged by developer. (Sat, 26 Apr 2025 11:24:02 GMT) Full text and rfc822 format available.

Message #10 received at 77941-done <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: kobarity <kobarity <at> gmail.com>
Cc: 77941-done <at> debbugs.gnu.org
Subject: Re: bug#77941: [PATCH] Fix Python block end predicates
Date: Sat, 26 Apr 2025 14:23:40 +0300
> Date: Sun, 20 Apr 2025 23:56:29 +0900
> From: kobarity <kobarity <at> gmail.com>
> 
> In the process of looking into #77620, I noticed bugs in the
> end-of-block detection functions in python.el.  If there is a comment
> on the last line of the block, `python-info-statement-ends-block-p'
> and `python-info-end-of-block-p' will not work correctly. 
> 
> Try the following Python code.
> 
> def func():
>     return 0  # Comment
> 
> When the point is located after "0" of the return statement, both
> `python-info-statement-ends-block-p' and `python-info-end-of-block-p'
> return nil.  If there is no comment on the line, they return t as
> expected.
> 
> This bug affects `python-nav-forward-sexp'.  In the above example, if
> the point is located at the beginning of "def func()" line,
> (python-nav-forward-sexp) moves the point to after "0".  This is the
> expected behavior.
> 
> However, if we execute (python-nav-forward-sexp -1) there, it moves
> the point to "0". This is not the expected behavior.  If there is no
> comment, it moves the point to the beginning of "def func()" line.
> 
> Attached is a patch that fixes this problem.

Thanks, installed, and closing the bug.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 25 May 2025 11:24:19 GMT) Full text and rfc822 format available.

This bug report was last modified 25 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.