targets.vim icon indicating copy to clipboard operation
targets.vim copied to clipboard

Define argument source with longer separator (multiple characters).

Open DasOhmoff opened this issue 2 years ago • 2 comments

Hi. Thank you for your support.

I tried to implement a text object that is separated by logical operators, f.e the && operator. See following example (^ = cursor position, . = text object range):

   ..................
if(obj.Method().Bla() && condition)
          ^

My idea was to use the argument source, as it has the exact same functionality, the only difference is the separator (which is , instead of &&). I tried to extend the targets mapping through the following way:

autocmd User targets#mappings#user call targets#mappings#extend(
\ {
\   '&': {'argument': [{'o': '[([]', 'c': '[])]', 's': '\(&&\)'}]}
\ })

But this does not seem to be working. I think the problem is that the separator is expected to be exactly a single character long.

How can I implement such a feature? It would be great if there was something like this that we could use, it would open many doors to create custom text operators.

DasOhmoff avatar Nov 11 '21 08:11 DasOhmoff

I really wanted to implement logical statement text objects today, and this is holding me back. I was told in my topic https://github.com/wellle/targets.vim/issues/254 that these are regexes but I suspect they are not, so it's very strange that they're referred to as regexes. Let's look at the code to see what would need to change to make this work. I want logical statement text objects REAL bad right now.

unphased avatar Mar 17 '22 04:03 unphased

OK from the code e.g. implementation of argument text object we can see that some simple regexes are built and used for matching, but the mechanism seems to be that of moving the cursor around (?) and testing that against these simple regexes.

It looks like following the template for plugins would be more suitable for something that requires multi character separators. But I worry about ending up having to test a ton of edgecases, and there are a ton of targets features that I wouldn't know how to begin properly testing. Hmm.

unphased avatar Mar 17 '22 05:03 unphased