nvim-treehopper icon indicating copy to clipboard operation
nvim-treehopper copied to clipboard

Include trailing seperators/whitespace on `c` or `d`

Open FredeEB opened this issue 2 years ago • 2 comments

First, thanks for your work on this plugin, I use it habitually at this point.

There's one thing I'm missing though, but I have no idea if it's possible.

With this keybind

onoremap m :lua require('tsht').nodes<cr>

Consider this line

local cursor_node = root:descendant_for_range(lnum, col, lnum, col)
                                  cursor here ^

Here, let's say I'd like to delete lnum under the cursor with dma in normal mode, I get this

local cursor_node = root:descendant_for_range(, col, lnum, col)
                                  cursor here ^

But what I'd really like, is deleting all the way up to the next argument like this

local cursor_node = root:descendant_for_range(col, lnum, col)
                                  cursor here ^

I might give this a shot myself, but an approach could be to pass an argument to the nodes function, as to whether or not it should delete only around the current or up to the next node

FredeEB avatar Apr 24 '22 11:04 FredeEB

I'd accept a PR that adds something like this. I've introduced a opts parameter that can take a source function (a function returning the nodes to hint on, a node is a table with 4 entries { start_row, start_col, end_row, end_col }.

An option would be to also support source being a string to address the functions by name.

You could then add a new function that generates nodes - ideally basing it on the existing functions. E.g. you could maybe even run them and then post-process the nodes to extend the end

mfussenegger avatar Aug 01 '22 21:08 mfussenegger

Those are good suggestions. The only thing I'm really missing currently, is time :sweat_smile: So it might be a bit before I get to look at this. So if anyone else stumbles upon this, and wants to give it a shot, I'm not going to stop them :100:

FredeEB avatar Sep 05 '22 08:09 FredeEB