Method: VER::Text::Tag#comment

Defined in:
lib/ver/text/tag.rb

#commentObject

Comment all lines that the selection touches. Tries to maintain indent.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/ver/text/tag.rb', line 59

def comment
  comment = buffer.options.comment_line.to_s
  indent = nil
  lines = []

  each_line do |line, fc, tc|
    line_fc, line_tc = "#{line}.#{fc}", "#{line}.#{tc}"

    next if buffer.at_end == line_tc

    lines << line

    next if indent == 0 # can't get lower

    line = buffer.get("#{line}.#{fc}", "#{line}.#{tc}")

    next unless start = line =~ /\S/

    indent ||= start
    indent = start if start < indent
  end

  indent ||= 0

  buffer.undo_record do |record|
    lines.each do |line|
      record.insert("#{line}.#{indent}", comment)
    end
  end
end