Saturday, December 28, 2013

Re: Function to pipe data through external command ?

On 2013-12-27 10:51 -0800, ZyX wrote:

> 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).

On 2013-12-27 11:15 -0800, Gary Johnson wrote:

> For finer-grained selection, try Chip Campbell's vis.vim plugin:
> http://vim.sourceforge.net/scripts/script.php?script_id=1195
>
> It allows you to visually-select a portion of a line (or lines) and
> pass just that portion to a Vim command, including an external
> command.

Oh boy. Why is it that when I ask how to do something in Vim,
half the time, the answers are along the lines of "it's
somewhere in that thousand line long script" ? :-D

Thanks for your replies, though.

I'm not fluent enough in Vim script to be sure but it seems that
neither script provides a way of piping besides the native
":execute {range}!".

Seems then that it would be easier for me to setline() the
string somewhere and :execute {range}!{filter} on it. That would
disturb the terminal but if the alternative really is as
complicated as it looks from the scripts you've linked to, maybe
I'd better content myself with a quick hack until Vim acquires
the needed primitives.

--
André Majorel http://www.teaser.fr/~amajorel/
Subliminal message : Vim needs elastic tab stops.

--
--
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:

Post a Comment