all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Daniel Kraus <daniel@kraus.my>
Cc: 59677@debbugs.gnu.org
Subject: bug#59677: 30.0.50; Error when calling (treesit-end-of-defun)
Date: Tue, 29 Nov 2022 13:27:43 +0100	[thread overview]
Message-ID: <m15yeyymgw.fsf@yahoo.es> (raw)
In-Reply-To: <87lenuko4o.fsf@kraus.my> (Daniel Kraus's message of "Tue, 29 Nov 2022 12:08:49 +0100")

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	other threads:[~2022-11-29 12:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-29 11:08 bug#59677: 30.0.50; Error when calling (treesit-end-of-defun) Daniel Kraus
2022-11-29 12:27 ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-11-29 12:35   ` Daniel Kraus
2022-12-02  5:17 ` Yuan Fu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m15yeyymgw.fsf@yahoo.es \
    --to=bug-gnu-emacs@gnu.org \
    --cc=59677@debbugs.gnu.org \
    --cc=daniel@kraus.my \
    --cc=mardani29@yahoo.es \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.