bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#58711: Treesit hangs when calling treesit-search-forward


From: Yuan Fu
Subject: bug#58711: Treesit hangs when calling treesit-search-forward
Date: Thu, 10 Nov 2022 00:14:27 -0800


> On Nov 9, 2022, at 10:44 PM, Wilhelm Kirschbaum <wilhelm@floatpays.co.za> 
> wrote:
> 
> I finally had some time to have a look. I don't see any more issues, thank 
> you for the fantastic work on this. The defun-type-regexp is not enough to 
> identify a defun in elixir this is the query I am using currently:
> 
> (defvar elixir--treesit-query-defun
>   (let ((query `((call
>      target: (identifier) @type
>      (arguments
>       [
>        (alias) @name
>        (identifier) @name
>        (call target: (identifier)) @name
>        (binary_operator
>         left: (call target: (identifier)) @name
>         operator: "when")
>        ])
>      (:match ,elixir--definition-keywords-re @type)
>      ))))
>     (treesit-query-compile 'elixir query)))
> 
> Regex will work in most cases I guess, but does not really deal with more 
> complex queries for more complex cases like in elixir as there is not one 
> type which is always the defun. elixir relies heavily on macros and different 
> defun macros can be defined on the fly.

You can try the following procedure: use a regex to find the next/previous 
call, then perform some check on whether it’s indeed a defun, if not, keep 
searching for the next/previous call.


> Maybe if there is an option for using either a regex or a function? 

Yes, instead of a regex you can pass a predicate function.

> 
> I am also not sure how forward-sexp can work with the current 
> treesit-search-forward-goto function as it does not take into consideration 
> the level. Is there perhaps a way to move forward/backward, but do not jump 
> to parents or children? 

If you want to move in the same level, perhaps you can use 
treesit-next/prev/sibling?

Yuan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]