Subject: bug#59788: closed (Re: bug#59788: 29.0.60; [PATCH] Make treesit-end-of-defun handle nil node)

From: [email-masked] (GNU bug Tracking System)
Date: Mon, 05 Dec 2022 06:23:02 +0000

Your bug report

#59788: 29.0.60; [PATCH] Make treesit-end-of-defun handle nil node

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

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

Subject: Re: bug#59788: 29.0.60; [PATCH] Make treesit-end-of-defun handle nil node
From: Yuan Fu <[email-masked]>
To: Theodor Thornhill <[email-masked]>
Cc: [email-masked], [email-masked]
Date: Sun, 4 Dec 2022 22:22:41 -0800
List-Id: <debbugs-submit.debbugs.gnu.org>

Theodor Thornhill <[email-masked]> writes:

> On 3 December 2022 07:33:46 CET, Eli Zaretskii <[email-masked]> wrote:
>>> Cc: [email-masked], [email-masked]
>>> From: Theodor Thornhill <[email-masked]>
>>> Date: Fri, 02 Dec 2022 21:45:59 +0100
>>> 
>>> However, I notice that treesit-beginning-of-defun returns t after it is
>>> done.  Is there a reason for end-of-defun not to return the same?
>>
>>The return value of end-of-defun is not documented, so it can be anything.
>
> Ok thanks, then I think this patch is ok now :)
>
> Theo

I think I applied a similar patch sent in another bug report, closing
this. Thanks as always :-)

Yuan

Subject: 29.0.60; [PATCH] Make treesit-end-of-defun handle nil node
From: Theodor Thornhill <[email-masked]>
To: [email-masked]
Date: Fri, 02 Dec 2022 21:45:59 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi Eli, Yuan and others,

mark-defun errors when node is missing in the call to goto-char.

Repro:

emacs -Q
find-file xdisp.c
M-g M-g 450 RET
M-x mark-defun

Observe that emacs is erroring.

This patch fixes this bug.  However, I notice that
treesit-beginning-of-defun returns t after it is done.  Is there a
reason for end-of-defun not to return the same?

Theo

>From 5e85e6e23f6dde43fc6433bed819c6d9f827007c Mon Sep 17 00:00:00 2001
From: Theodor Thornhill <[email-masked]>
Date: Fri, 2 Dec 2022 21:40:50 +0100
Subject: [PATCH] Make treesit-end-of-defun handle nil node

* lisp/treesit.el (treesit-end-of-defun): Change from 'let*' to
'when-let*'.
---
 lisp/treesit.el | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lisp/treesit.el b/lisp/treesit.el
index 0de0e283c3..e0949d7328 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -1611,9 +1611,9 @@ treesit-end-of-defun
   "Tree-sitter `end-of-defun' function."
   ;; Why not simply get the largest node at point: when point is at
   ;; (point-min), that gives us the root node.
-  (let* ((node (treesit-search-forward
-                (treesit-node-at (point)) treesit-defun-type-regexp t t))
-         (top (treesit--defun-maybe-top-level node)))
+  (when-let* ((node (treesit-search-forward
+                     (treesit-node-at (point)) treesit-defun-type-regexp t t))
+              (top (treesit--defun-maybe-top-level node)))
     (goto-char (treesit-node-end top))))
 
 ;;; Activating tree-sitter
-- 
2.34.1