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 wanted to have a mapping to jump to whatever is the current "parent" node, and found the go_to_context() function which works great! But it only jumps to contexts that are also displayed by the plugin, and I'd like this mapping to be more granular and also consider contexts that are in view, or hidden by my max_lines setting.
I managed to hack something together if I expose the iter_context_parents function from the plugin:
-- add in `lua/treesitter-context/context.lua`M.iter_context_parents=iter_context_parents-- in my mapping:localcontext=require('treesitter-context.context')
localcursor=vim.api.nvim_win_get_cursor(0)
localrow=cursor[1]
localparents, _query=context.iter_context_parents(0, { row-1, 0, row-1, 0 })()
fori=1, #parentsdolocalparent_row=parents[i]:range() +1ifparent_row<rowthenvim.cmd([[ normal! m' ]])
vim.api.nvim_win_set_cursor(0, { parent_row, 0 })
vim.cmd.normal('^')
returnendend
This seems to work how I want, and now I wonder what it would take to implement a cleaner version of this inside the plugin, or what bits could be exposed to allow a custom mapping like this (iter_context_parents seems a bit too low-level).
Also not sure if there's a way to do this using e.g. nvim-treesitter-textobjects, it seems the magic sauce that's needed are the queries collected in this plugin.
The text was updated successfully, but these errors were encountered:
I wanted to have a mapping to jump to whatever is the current "parent" node, and found the
go_to_context()
function which works great! But it only jumps to contexts that are also displayed by the plugin, and I'd like this mapping to be more granular and also consider contexts that are in view, or hidden by mymax_lines
setting.I managed to hack something together if I expose the
iter_context_parents
function from the plugin:This seems to work how I want, and now I wonder what it would take to implement a cleaner version of this inside the plugin, or what bits could be exposed to allow a custom mapping like this (
iter_context_parents
seems a bit too low-level).Also not sure if there's a way to do this using e.g.
nvim-treesitter-textobjects
, it seems the magic sauce that's needed are the queries collected in this plugin.The text was updated successfully, but these errors were encountered: