# This is a script for vim-ruby for sorting collections # # Author: Igor Vergeichik # Sponsor: Tom Sawyer # Copyright (c) 2002 Tom Saywer class YCollection def initialize(rule) @buffer=VIM::Buffer.current @window=VIM::Window.current @lnum = @window.cursor[0] @key=@buffer[@lnum].scan(/^([^:]+[^\s])\s*:/) # Find collection bounds r = bounds # If collection found - resort it replace(r, resort((parse r), rule)) if r[1]>0 end # Detect bounds of YAML collection # Input: no # Output: Array - range of detected collection def bounds lnum = @lnum # If line begins with a dash - this is one of collection items if @buffer[lnum]=~/\s*-/ coll_bounds(lnum) else # otherwise we need to find parent item ind = VIM::evaluate("indent(#{lnum})").to_i while lnum>0 if VIM::evaluate("indent(#{lnum})").to_i0 curr_ind = VIM::evaluate("indent(#{ln})").to_i break if curr_inda}