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