Support/tmvc/lib/ruby_tm_helpers.rb
# this method only applies when the whole document contents are sent in
this method only applies when the whole document contents are sent in
this method only applies when the whole document contents are sent in
def tm_expanded_selection(options = {})
  text=ENV['TM_SELECTED_TEXT'].to_s
  return text unless text.empty?
  options = {
    :input_type => :doc,
    :input => nil,
    :forward => /\w*/i,
    :backward => /\w*/i,
    :line_number => ENV['TM_LINE_NUMBER'].to_i,
    :col_number => ENV['TM_COLUMN_NUMBER'].to_i
  }.merge(options)
  col_number, line_number = options[:col_number], options[:line_number]
  doc = options[:input] ||= $stdin.read
  line = 
    case options[:input_type]
    when :doc  then doc.split("\n")[line_number - 1]
    when :line then doc
    else 
      raise "Can't handle input_type #{options[:input_type]} for tm_expanded_selection"
    end
  last_part = line[ (col_number - 1)..-1]
  first_part = line[ 0..col_number - 2]
  last_part.gsub!(/^(#{options[:forward]}){0,1}.*$/i) { $1 }
  first_part.reverse!
  first_part.gsub!(/^(#{options[:backward]}){0,1}.*$/i) { $1 }
  first_part.reverse!
  first_part + last_part
end
def tm_expanded_selection ( options = { } ) text = ENV [ 'TM_SELECTED_TEXT' ] . to_s return text unless text . empty? options = { :input_type => :doc , :input => nil , :forward => / \w * /i , :backward => / \w * /i , :line_number => ENV [ 'TM_LINE_NUMBER' ] . to_i , :col_number => ENV [ 'TM_COLUMN_NUMBER' ] . to_i } . merge ( options ) col_number , line_number = options [ :col_number ] , options [ :line_number ] doc = options [ :input ] ||= $stdin . read line = case options [ :input_type ] when :doc then doc . split ( "\n" ) [ line_number - 1 ] when :line then doc else raise "Can't handle input_type #{options[:input_type]} for tm_expanded_selection" end last_part = line [ ( col_number - 1 ) .. - 1 ] first_part = line [ 0 .. col_number - 2 ] last_part . gsub! ( / ^( #{ options [ :forward ] } ){0,1}.*$ /i ) { $1 } first_part . reverse! first_part . gsub! ( / ^( #{ options [ :backward ] } ){0,1}.*$ /i ) { $1 } first_part . reverse! first_part + last_part end
this method only applies when the whole document contents are sent in
this method only applies when the whole document contents are sent in
options
<not_specific>