You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I miss the [[ and ]] features of vim-sexp to jump to the toplevel form start and end. I initially implemented a solution by iterating the api function move_to_parent_form_{start,end} used in (. It worked fine but it was neater to create new api functions move_to_root_{start,end}. The code is based on move_to_parent_form (Apologies I don't know enough treesitter and nvim lua to know if there's a better approach!):
-- Helper to get cursor pos for form edge.localfunctionform_node_edge_pos(form_node, direction, lang)
localform_edges=lang.get_form_edges(form_node)
localedge_cursor_pos= {
form_edges[direction].range[1] +1,
form_edges[direction].range[2]
}
returnedge_cursor_posendlocalfunctionmove_to_root(direction)
locallang=langs.get_language_api()
localcur_node=ts.get_node_at_cursor()
localnearest_form_node=traversal.find_nearest_form(cur_node, { lang=lang })
ifnotnearest_form_nodeornearest_form_node:type() =="source" thenreturnendlocalcur_cursor_pos=vim.api.nvim_win_get_cursor(0)
localform_node_to_move_to=nearest_form_noderepeatprev_form=form_node_to_move_toform_node_to_move_to=lang.get_node_root(form_node_to_move_to):parent()
untilnotform_node_to_move_toorform_node_to_move_to:type() =="source" oris_cursor_at_form_edge(form_node_to_move_to, direction,
form_node_edge_pos(prev_form, direction, lang), lang)
form_node_to_move_to=prev_formmove_to_form_edge(form_node_to_move_to, direction, lang)
endfunctionM.move_to_root_start()
move_to_root(MOTION_DIRECTIONS.LEFT)
endfunctionM.move_to_root_end()
move_to_root(MOTION_DIRECTIONS.RIGHT)
end
The text was updated successfully, but these errors were encountered:
I miss the
[[
and]]
features of vim-sexp to jump to the toplevel form start and end. I initially implemented a solution by iterating the api functionmove_to_parent_form_{start,end}
used in(
. It worked fine but it was neater to create new api functionsmove_to_root_{start,end}
. The code is based onmove_to_parent_form
(Apologies I don't know enough treesitter and nvim lua to know if there's a better approach!):The text was updated successfully, but these errors were encountered: