Subject: bug#77941: closed (Re: bug#77941: [PATCH] Fix Python block end predicates)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 26 Apr 2025 11:24:02 +0000

Your bug report

#77941: [PATCH] Fix Python block end predicates

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].

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

Subject: Re: bug#77941: [PATCH] Fix Python block end predicates
From: Eli Zaretskii <[email-masked]>
To: kobarity <[email-masked]>
Cc: [email-masked]
Date: Sat, 26 Apr 2025 14:23:40 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

> Date: Sun, 20 Apr 2025 23:56:29 +0900
> From: kobarity <[email-masked]>
> 
> 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.

Subject: [PATCH] Fix Python block end predicates
From: kobarity <[email-masked]>
To: [email-masked]
Date: Sun, 20 Apr 2025 23:56:29 +0900
List-Id: <debbugs-submit.debbugs.gnu.org>

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'