bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#59677: 30.0.50; Error when calling (treesit-end-of-defun)


From: Daniel Martín
Subject: bug#59677: 30.0.50; Error when calling (treesit-end-of-defun)
Date: Tue, 29 Nov 2022 13:27:43 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (darwin)

Daniel Kraus <daniel@kraus.my> writes:

> Hi,
>
> I tried the latest -ts-modes and ran into a problem with the
> symbol-overlay ( https://github.com/wolray/symbol-overlay )
> package.
>
> The problem is that `(end-of-defun)` calls `(treesit-end-of-defun)`
> when in a ...-ts-mode and this function seems to raise an error when
> point is not inside a function.
>
> Steps to reproduce:
> - emacs -Q
> - find-file "foo.py"
> - Then if you run `M-: (end-of-defun)` it works as expected.
> - After switching to `M-x python-ts-mode`,
>   the same command raises an error.

The error is signaled by the goto-char call in treesit-end-of-defun.
Protecting it from possible nil node positions fixes the issue for me
(there is a similar check in treesit-beginning-of-defun):

diff --git a/lisp/treesit.el b/lisp/treesit.el
index 8f092f475d..45a4d3c764 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -1614,7 +1614,9 @@ treesit-end-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))))
+    (when top
+      (goto-char (treesit-node-end top))
+      t)))
 
 ;;; Activating tree-sitter
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]