[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#73404: 30.0.50; [forward/kill/etc]-sexp commands do not behave as ex
From: |
Juri Linkov |
Subject: |
bug#73404: 30.0.50; [forward/kill/etc]-sexp commands do not behave as expected in tree-sitter modes |
Date: |
Wed, 18 Dec 2024 09:37:39 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/31.0.50 (x86_64-pc-linux-gnu) |
While testing treesit-forward-sexp-list, I discovered that
thing-navigation functions are not restricted to named nodes.
I wonder if there a reason to find anonymous nodes as things?
The problem was found with the node "unless" in Ruby:
unless cond
a += 1
else
b -= 1
end
Here the named node 'unless' has exactly the same name
as the anonymous node with the text "unless":
(unless "unless" condition: (identifier)
Finding anonymous nodes breaks forward-sexp when point is on "unless":
un-!-less cond
a += 1
else
b -= 1
end
because (treesit-thing-at (point) 'sexp t) finds
#<treesit-node "unless" in 156-162>
instead of
#<treesit-node unless in 156-203>
Also this breaks backward-sexp and backward-up-list
because treesit--thing-sibling finds
the anonymous node "unless" as a previous sibling
instead of the named node 'unless' as a parent.
Would the right solution be to check if the found thing
is a named node? With something like:
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 18200acf53f..9ad879ee40c 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -2711,6 +2774,7 @@ treesit--thing-sibling
(lambda (n) (>= (treesit-node-start n) pos))))
(iter-pred (lambda (node)
(and (treesit-node-match-p node thing t)
+ (treesit-node-check node 'named)
(funcall pos-pred node))))
(sibling nil))
(when cursor
@@ -2760,6 +2824,7 @@ treesit-thing-at
(let* ((cursor (treesit-node-at pos))
(iter-pred (lambda (node)
(and (treesit-node-match-p node thing t)
+ (treesit-node-check node 'named)
(if strict
(< (treesit-node-start node) pos)
(<= (treesit-node-start node) pos))
- bug#73404: 30.0.50; [forward/kill/etc]-sexp commands do not behave as expected in tree-sitter modes, (continued)
- bug#73404: 30.0.50; [forward/kill/etc]-sexp commands do not behave as expected in tree-sitter modes, Juri Linkov, 2024/12/12
- bug#73404: 30.0.50; [forward/kill/etc]-sexp commands do not behave as expected in tree-sitter modes, Eli Zaretskii, 2024/12/12
- bug#73404: 30.0.50; [forward/kill/etc]-sexp commands do not behave as expected in tree-sitter modes, Juri Linkov, 2024/12/12
- bug#73404: 30.0.50; [forward/kill/etc]-sexp commands do not behave as expected in tree-sitter modes, Juri Linkov, 2024/12/12
- bug#73404: 30.0.50; [forward/kill/etc]-sexp commands do not behave as expected in tree-sitter modes, Juri Linkov, 2024/12/12
- bug#73404: 30.0.50; [forward/kill/etc]-sexp commands do not behave as expected in tree-sitter modes, Juri Linkov, 2024/12/12
- bug#73404: 30.0.50; [forward/kill/etc]-sexp commands do not behave as expected in tree-sitter modes, Eli Zaretskii, 2024/12/12
- bug#73404: 30.0.50; [forward/kill/etc]-sexp commands do not behave as expected in tree-sitter modes, Juri Linkov, 2024/12/13
- bug#73404: 30.0.50; [forward/kill/etc]-sexp commands do not behave as expected in tree-sitter modes, Eli Zaretskii, 2024/12/14
- bug#73404: 30.0.50; [forward/kill/etc]-sexp commands do not behave as expected in tree-sitter modes, Juri Linkov, 2024/12/14
- bug#73404: 30.0.50; [forward/kill/etc]-sexp commands do not behave as expected in tree-sitter modes,
Juri Linkov <=
- bug#73404: 30.0.50; [forward/kill/etc]-sexp commands do not behave as expected in tree-sitter modes, Yuan Fu, 2024/12/18
- bug#74963: Ambiguous treesit named and anonymous nodes in ruby-ts-mode, Juri Linkov, 2024/12/19
- bug#74963: Ambiguous treesit named and anonymous nodes in ruby-ts-mode, Yuan Fu, 2024/12/23
- bug#74963: Ambiguous treesit named and anonymous nodes in ruby-ts-mode, Juri Linkov, 2024/12/24
- bug#74963: Ambiguous treesit named and anonymous nodes in ruby-ts-mode, Juri Linkov, 2024/12/24
- bug#74963: Ambiguous treesit named and anonymous nodes in ruby-ts-mode, Dmitry Gutov, 2024/12/24
- bug#74963: Ambiguous treesit named and anonymous nodes in ruby-ts-mode, Juri Linkov, 2024/12/25
- bug#74963: Ambiguous treesit named and anonymous nodes in ruby-ts-mode, Dmitry Gutov, 2024/12/25
- bug#74963: Ambiguous treesit named and anonymous nodes in ruby-ts-mode, Juri Linkov, 2024/12/27
- bug#74963: Ambiguous treesit named and anonymous nodes in ruby-ts-mode, Juri Linkov, 2024/12/24