unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Theodor Thornhill via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 59788@debbugs.gnu.org
Cc: casouri@gmail.com, eliz@gnu.org
Subject: bug#59788: 29.0.60; [PATCH] Make treesit-end-of-defun handle nil node
Date: Fri, 02 Dec 2022 21:45:59 +0100	[thread overview]
Message-ID: <87h6ydfsag.fsf@thornhill.no> (raw)

[-- Attachment #1: Type: text/plain, Size: 366 bytes --]


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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Make-treesit-end-of-defun-handle-nil-node.patch --]
[-- Type: text/x-diff, Size: 1139 bytes --]

From 5e85e6e23f6dde43fc6433bed819c6d9f827007c Mon Sep 17 00:00:00 2001
From: Theodor Thornhill <theo@thornhill.no>
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


             reply	other threads:[~2022-12-02 20:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-02 20:45 Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-12-03  6:33 ` bug#59788: 29.0.60; [PATCH] Make treesit-end-of-defun handle nil node Eli Zaretskii
2022-12-03  7:00   ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-05  6:22 ` Yuan Fu via Bug reports for GNU Emacs, the Swiss army knife of text editors

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=87h6ydfsag.fsf@thornhill.no \
    --to=bug-gnu-emacs@gnu.org \
    --cc=59788@debbugs.gnu.org \
    --cc=casouri@gmail.com \
    --cc=eliz@gnu.org \
    --cc=theo@thornhill.no \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).