On Friday 05 July 2002 03:11 pm, Steve Tuckner wrote:
> I am want to build a class or set of classes to use in VIM so that
> I can more easily script vim/ruby. The problem with the current set
> of classes is that I want VIM::Buffer, VIM::Window, and the buffer
> lists to act
>
> just like arrays so that I could do the following:
> : ruby $curbuf.sort {|a,b| a.to_i <=> b.to_i}

Or you could just mix in each() to VIM::Buffer and VIM::Window...
now you can sort them, etc.

ruby <<EOF
module VIM
  class Buffer
   include Enumerable
   # each line in buffer...
   def each(&block)
     (1..count).each { |n| block.call(self[n]) }
   end
   # each buffer...
   def self.each(&block)
     (0..count-1).each { |n| block.call(self[n]) }
   end
  end
  class Window
   include Enumerable
   # each window...
   def self.each(&block)
     (0..count-1).each { |n| block.call(self[n]) }
   end
 end
end

def p(s)
  b = VIM::Buffer.current
  b.append(b.count, s.inspect)
end

# print out all the lines of this file
def beach(&block)
  b = VIM::Buffer.current
  b.each(&block)
end
beach { |s| puts s }

# append all the lines of this file to the end.
b = VIM::Buffer.current
b.sort.each { |s| p "s: #{s}" }

EOF

-- 
Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE