Sha256: d6427ef308094dd438822b25f526336135ed289f5eaacc376984ca860024adc2
Contents?: true
Size: 856 Bytes
Versions: 9
Compression:
Stored size: 856 Bytes
Contents
module Redcar class Document class Indentation def initialize(doc, tab_width, soft_tabs) @doc, @tab_width, @soft_tabs = doc, tab_width, soft_tabs end def get_level(ix) whitespace_prefix(ix).scan(indent_consuming_regex).length end def whitespace_prefix(ix) line = @doc.get_line(ix) line.match(/^(\s*)([^\s]|$)/)[1].chomp end def set_level(ix, level) offset = @doc.offset_at_line(ix) prefix = whitespace_prefix(ix) if @soft_tabs @doc.replace(offset, prefix.length, " "*@tab_width*level) else @doc.replace(offset, prefix.length, "\t"*level) end end private def indent_consuming_regex /( {0,#{@tab_width - 1}}\t| {#{@tab_width}})/ end end end end
Version data entries
9 entries across 9 versions & 1 rubygems