[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#60355: 29.0.60; Tree sitter incorrectly handles of PRED for treesit-
From: |
Wilhelm H Kirschbaum |
Subject: |
bug#60355: 29.0.60; Tree sitter incorrectly handles of PRED for treesit-defun-type-regexp |
Date: |
Tue, 27 Dec 2022 14:09:29 +0200 |
User-agent: |
mu4e 1.9.3; emacs 29.0.60 |
When `treesit-defun-type-regexp` is set with a cons cell (regexp .
some-pred)
the following case does not get handled as expected when calling
(end-of-defun):
```elixir
defmodule Example do
def foo() do ; regexp match, pred match
end
;; <point here>
@impl true ; regexp match, pred does not match
def bar() do ; regexp match, pred match
end
;; <should jump to here>
def baz() do
end
end
;; <jumps to point here>
```
The function `treesit--things-around` only looks at the PRED after
it searches forward and
would then not be aware of the non matching node. The following
change works for my case
where search-forward takes in the PRED, not just the regexp:
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 2130cd0061..7997509f50 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -1776,7 +1776,13 @@ treesit--things-around
node "" nil nil t))
node))
(result (list nil nil nil))
- (pred (or pred (lambda (_) t))))
+ (pred (if (null pred)
+ (lambda (node)
+ (string-match-p regexp (treesit-node-type
node)))
+ (lambda (node)
+ (and (string-match-p regexp (treesit-node-type
node))
+ (funcall pred node))))))
+
;; 1. Find previous and next sibling defuns.
(cl-loop
for idx from 0 to 1
@@ -1798,12 +1804,10 @@ treesit--things-around
do (cl-loop for cursor = (when node
(save-excursion
(treesit-search-forward
- node regexp backward
backward)))
+ node pred backward backward)))
then (treesit-node-parent cursor)
while cursor
- if (and (string-match-p
- regexp (treesit-node-type cursor))
- (funcall pred cursor)
+ if (and (funcall pred cursor)
(funcall pos-pred cursor))
do (setf (nth idx result) cursor)))
;; 2. Find the parent defun.
Hope this makes sense,
Wilhelm
ps. Sorry about the email swapping, think it should be fixed now.
- bug#60355: 29.0.60; Tree sitter incorrectly handles of PRED for treesit-defun-type-regexp,
Wilhelm H Kirschbaum <=