unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#59788: 29.0.60; [PATCH] Make treesit-end-of-defun handle nil node
@ 2022-12-02 20:45 Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-12-03  6:33 ` Eli Zaretskii
  2022-12-05  6:22 ` Yuan Fu via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 2 replies; 4+ messages in thread
From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-12-02 20:45 UTC (permalink / raw)
  To: 59788; +Cc: casouri, eliz

[-- 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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#59788: 29.0.60; [PATCH] Make treesit-end-of-defun handle nil node
  2022-12-02 20:45 bug#59788: 29.0.60; [PATCH] Make treesit-end-of-defun handle nil node Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-12-03  6:33 ` 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
  1 sibling, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2022-12-03  6:33 UTC (permalink / raw)
  To: Theodor Thornhill; +Cc: 59788, casouri

> Cc: casouri@gmail.com, eliz@gnu.org
> From: Theodor Thornhill <theo@thornhill.no>
> Date: Fri, 02 Dec 2022 21:45:59 +0100
> 
> 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?

The return value of end-of-defun is not documented, so it can be anything.





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#59788: 29.0.60; [PATCH] Make treesit-end-of-defun handle nil node
  2022-12-03  6:33 ` Eli Zaretskii
@ 2022-12-03  7:00   ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; 4+ messages in thread
From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-12-03  7:00 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 59788, casouri



On 3 December 2022 07:33:46 CET, Eli Zaretskii <eliz@gnu.org> wrote:
>> Cc: casouri@gmail.com, eliz@gnu.org
>> From: Theodor Thornhill <theo@thornhill.no>
>> Date: Fri, 02 Dec 2022 21:45:59 +0100
>> 
>> 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?
>
>The return value of end-of-defun is not documented, so it can be anything.

Ok thanks, then I think this patch is ok now :)

Theo





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#59788: 29.0.60; [PATCH] Make treesit-end-of-defun handle  nil node
  2022-12-02 20:45 bug#59788: 29.0.60; [PATCH] Make treesit-end-of-defun handle nil node Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2022-12-03  6:33 ` Eli Zaretskii
@ 2022-12-05  6:22 ` Yuan Fu via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 0 replies; 4+ messages in thread
From: Yuan Fu via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-12-05  6:22 UTC (permalink / raw)
  To: Theodor Thornhill; +Cc: eliz, 59788-done


Theodor Thornhill <theo@thornhill.no> writes:

> On 3 December 2022 07:33:46 CET, Eli Zaretskii <eliz@gnu.org> wrote:
>>> Cc: casouri@gmail.com, eliz@gnu.org
>>> From: Theodor Thornhill <theo@thornhill.no>
>>> Date: Fri, 02 Dec 2022 21:45:59 +0100
>>> 
>>> 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?
>>
>>The return value of end-of-defun is not documented, so it can be anything.
>
> Ok thanks, then I think this patch is ok now :)
>
> Theo

I think I applied a similar patch sent in another bug report, closing
this. Thanks as always :-)

Yuan





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-12-05  6:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-02 20:45 bug#59788: 29.0.60; [PATCH] Make treesit-end-of-defun handle nil node Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-03  6:33 ` 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

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).