From 520a4e12f8e6e42d0c66cc6b3cf3be05c411fe6f Mon Sep 17 00:00:00 2001
From: Yuan Fu <casouri@gmail.com>
Date: Thu, 1 Dec 2022 21:19:14 -0800
Subject: [PATCH] ; * lisp/treesit.el (treesit-end-of-defun): Guard against nil
 value.

---
 lisp/treesit.el | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lisp/treesit.el b/lisp/treesit.el
index 0de0e283c3b..f3c03daf7e0 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -1614,7 +1614,12 @@ ARG is the same as in `beginning-of-defun'."
   (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))))
+    ;; Technically `end-of-defun' should only call this function when
+    ;; point is at the beginning of a defun, so TOP should always be
+    ;; non-nil, but things happen, and we want to be safe, so check
+    ;; for TOP anyway.
+    (when top
+      (goto-char (treesit-node-end top)))))
 
 ;;; Activating tree-sitter
 
-- 
2.39.5