martanne / vis

A vi-like editor based on Plan 9's structural regular expressions
Other
4.27k stars 262 forks source link

Support tag blocks as text objects #57

Open martanne opened 9 years ago

martanne commented 9 years ago

See :help tag-blocks in vim. Add two new functions text_object_tag{,_outer} to text-object.c

martanne commented 8 years ago

With the latest commits it should in principle be possible to define text objects (and motions) as Lua functions.

@TieDyedDevil do you want to give it a try, and implement tag blocks in Lua? You might need to extend the provided Lua API if some required functionality is not available.

pentlander commented 8 years ago

I had a basic working version of this in C a couple months back and now that I have a computer again I'm going to finish it. Would you rather it be done in Lua instead?

martanne commented 8 years ago

In general C is fine, some would say even preferable. However if the implementation turns out to be tricky and a Lua/LPeg based solution would be much simpler then doing it that way might be beneficial.

pentlander commented 8 years ago

The simple case of "dat" currently works with my code. However I realized that the more complicated cases would require you to keep track of the matching tags. For example, doing "dit" where the arrow is in the following:

<html>
    <a> <fake> <another> Text </onceagain> </a>
---------------------------^
</html>

should result in

<html>
    <a></a>
</html>

This works in Vim. It would be pretty complicated to do in C, so I think I'm going to give Lua a shot instead.

martanne commented 8 years ago

Yes as you noticed it is not completely trivial. That is the reason why I so far did not implement it and why I suggested doing it in Lua instead. Using LPeg might come in handy. Thus I initially tagged @TieDyedDevil because he contributed a few LPeg based lexers for syntax highlighting.

martanne commented 8 years ago

@pentlander did you make any progress?

ghost commented 4 years ago

The vis-pairs plugin supports XML/HTML tags - https://repo.or.cz/vis-pairs.git It can be used both interactively, and as a pure Lua module (it exports its motions and textobjects, and I vaguely remember that there was a way to tell it not to map any keys.)