Tags: if_ruby


Vim, recent if_ruby changes, and TwitVim

Futuro house Bram recently added a bunch of if_ruby (Ruby Interface) patches to Vim to add support for Ruby 1.9, improve overall support for Ruby, and fix a few problems. Of course, two of those patches affected TwitVim and I'll discuss them here. First, the good stuff: Patch 7.2.360 finally fixes the if_ruby Windows sockets problem. I used to recommend this unofficial patch but that won't be needed any more if the user has patch 7.2.360 or (the upcoming) Vim 7.3 or later.

Patch 7.2.374 allows VIM::evaluate() to return Ruby arrays or hashes instead of strings if the Vim expression results in a list or dictionary. This, unfortunately, did break TwitVim because TwitVim does the following:
    keys = VIM.evaluate('keys(a:parms)')
    keys = keys.split(/\n/)
If the parms dictionary has keys "user", "text", and "status", prior to patch 7.2.374, VIM.evaluate() will return "user\ntext\nstatus" and the next line will split it into the array ["user", "text", "status"]. After patch 7.2.374, VIM.evaluate() returns ["user", "text", "status"], causing the next line to hit a Ruby error because a Ruby array doesn't have a split() method.

How do we solve this problem? At first, I was thinking of checking for this Vim patch using a conditional like this:
    v:version > 702 || v:version == 702 && has("patch374")
In other words, Vim 7.3 and later are guaranteed to have patch 7.2.374 and we only check for the patch itself if the Vim version is 7.2. If I stick this expression into VIM.evaluate(), it'll return "1" if that patch is present and "0" otherwise. Then it occurred to me that there are two better ways to deal with this:

1. Make the Vim expression return a string regardless by doing an explicit join on the array:
    keys = VIM.evaluate('join(keys(a:parms), "\n")')
    keys = keys.split(/\n/)
2. Use Ruby's type introspection to see if a split is needed:
    keys = VIM.evaluate('keys(a:parms)')
    keys = keys.split(/\n/) if keys.is_a? String
I prefer the second approach because it is more efficient and a few years into the future, once everyone has upgraded their Vim installations past this patch, we can clean up the code easily by removing the second line. Thus, this fix is in TwitVim revision 82.

Ruby, Tcl, and Vim

Old Troy Park

After digging into the Vim mailing list archives, I found out why the networking code in Ruby/if_ruby was failing in Vim. It is because if_ruby.c didn't call NtInitialize() when setting up the if_ruby interface. Better yet, someone posted a patch for this a few months ago and Bram added a slight correction to the patch. Unfortunately, this patch still isn't in the Vim source distribution. Why? Because it was a drive-by patching. The original poster didn't follow up with Bram and Bram cannot include the patch without knowing the author's name. And so the bug remains to this day. I'll see if there's anything I can do to get this patch into the source (even if I have to take responsibility for it) but in the meantime, I added a Ruby version of the networking code to TwitVim in r13.

I also added a Tcl version of the code in r14. That was fun to do, mostly because I had no idea it was at all possible. I hadn't touched Tcl in over a decade and back then, the Tcl standard library didn't have half as many commands as it does now. One thing I noticed is the ActiveTcl 8.5 download doesn't include Tcllib by default. I don't know why ActiveState would omit such an important library component but it is easy to install using the teacup program afterwards.
create a fursona

Losing air


The driver's side rear tire is still losing air but only at the rate of 5 psi per day. It's a slow leak. I haven't found the leak yet so I've just been pumping it up every few days. I have my own air pump and I've also been using the free air at the gas station near work. I'll get someone to check it within the month.

Teck Cominco is buying Fording Coal. So I'll get cash and TCK stock, but at the same time, I'll be saying goodbye to yet another top-performing and high-yielding stock. Many in the investment community still do not realize what bargains income trusts have become in the wake of the Canadian tax scare two years ago, but other energy resource companies have taken notice. Of my five income trust picks, two have gotten bids. I'm sure many more income trusts that I've not been following have also been acquired. Market forces will eventually correct what the government has broken.

More TwitVim development and a problem with if_ruby...Collapse )