Thank you. I will spend some time over the weekend to try and have a look. On Fri, 11 Nov 2022 at 00:07, Yuan Fu wrote: > > > > On Nov 10, 2022, at 12:43 PM, Wilhelm Kirschbaum < > wilhelm@floatpays.co.za> wrote: > > > > Given the following code > > > > <.foo> ;; component, start_component > > ;; tag, start_tag > > ;; [cursor here 1)] end_tag > > ;; [cursor here 2] end_component > > > > and ast > > > > (fragment [0, 0] - [5, 0] > > (component [0, 0] - [3, 7] > > (start_component [0, 0] - [0, 6] > > (component_name [0, 1] - [0, 5] > > (function [0, 2] - [0, 5]))) > > (tag [1, 2] - [2, 8] > > (start_tag [1, 2] - [1, 7] > > (tag_name [1, 3] - [1, 6])) > > (end_tag [2, 2] - [2, 8] > > (tag_name [2, 4] - [2, 7]))) > > (end_component [3, 0] - [3, 7] > > (component_name [3, 2] - [3, 6] > > (function [3, 3] - [3, 6]))))) > > > > I do not know how to reliably move from cursor position 1 to start of > and from cursor position 2 to start of <.foo> > > The snippet below should take you to the corresponding open tag. > > (let ((end-node (treesit-search-forward-goto > (treesit-node-at (point)) > (rx (or "end_tag" "end_component" "end_slot")) t t))) > ;; Go to the corresponding start tag. > (goto-char (treesit-node-start (treesit-node-parent end-node)))) > > > > > as (treesit-search-forward (treesit-node-at (point)) (rx (or "end_tag" > "end_component" "end_slot")) t) on position 1 will not look backwards, but > find the <./foo> end_component. > > > > if i am at the point after the node, how do I find the node before the > point? once we have the node before the point we can find the correct > parent and then find the prev sibling to goto. > > > > Hope this makes sense. > > Yeah, if there is a function that gives you the node right before point, > treesit-search-forward would work as expected. I’ll see how to add this > functionality. > > Yuan