Friday, December 27, 2013

Re: Function to pipe data through external command ?

> Thanks but :{range}! only filters entire lines from the buffer.
> I need something finer grained.

You may use system() with 2 arguments, but your "finer grained" filter will be tricky. You can check out my translit3: it has command to transliterate selection. Command achieves the following task:

1. It transliterates whatever you have selected: i.e. works with character- and block-wise selections in addition to line-wise.
2. It does not alter any registers, jump list (except for last change jump list) or last selection. If you remove this requirement task will be far, far easier.
3. It add only one item to undo tree.

. Functions used to achieve this:
1. For character-wise selection:
1. To get characters that will be transliterated: https://sourceforge.net/p/translit3/code/ci/fc8da4b019def8f84fe2f426639a9e37ee9dc7e2/tree/autoload/translit3.vim#l2119
2. Just the next function deletes character range (guess it could be achieved with normal! without giving up the second restriction): http://sourceforge.net/p/translit3/code/ci/fc8da4b019def8f84fe2f426639a9e37ee9dc7e2/tree/autoload/translit3.vim#l2146.
3. And the third one puts given text in given position (the least verbose one): http://sourceforge.net/p/translit3/code/ci/fc8da4b019def8f84fe2f426639a9e37ee9dc7e2/tree/autoload/translit3.vim#l2177.

Note: functions operate on lists like "getline(start, end)" or "readfile()" return. Without my patch that adds "system()" equivalent that returns same lists and accepts such list as a second argument you have to rely on "split()" and "join()" (assuming you do not care about possible NULs in filtered lines or filter result).

2. For line-wise and block-wise selections: http://sourceforge.net/p/translit3/code/ci/fc8da4b019def8f84fe2f426639a9e37ee9dc7e2/tree/autoload/translit3.vim#l2233 (note: block-wise part contains bug: it transliterates one more line. You need to change "line<=eline" conditions into "line<eline". I will release the fix soon).

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: