lib/textbringer/window.rb in textbringer-0.2.7 vs lib/textbringer/window.rb in textbringer-0.2.8
- old
+ new
@@ -352,20 +352,20 @@
def highlight
@highlight_on = {}
@highlight_off = {}
return if !@@has_colors || !CONFIG[:syntax_highlight] || @buffer.binary?
- syntax_table = @buffer.mode.syntax_table
- return if syntax_table.empty?
+ syntax_table = @buffer.mode.syntax_table || DEFAULT_SYNTAX_TABLE
if @buffer.bytesize < CONFIG[:highlight_buffer_size_limit]
base_pos = @buffer.point_min
s = @buffer.to_s
else
base_pos = @buffer.point
len = columns * (lines - 1) / 2 * 3
s = @buffer.substring(@buffer.point, @buffer.point + len).scrub("")
end
+ return if !s.valid_encoding?
re_str = syntax_table.map { |name, re|
"(?<#{name}>#{re})"
}.join("|")
re = Regexp.new(re_str)
names = syntax_table.keys
@@ -675,9 +675,12 @@
"U+%04X" % c.ord
end
end
def escape(s)
+ if !s.valid_encoding?
+ s = s.b
+ end
if @buffer.binary?
s.gsub(/[\0-\b\v-\x1f\x7f]/) { |c|
"^" + (c.ord ^ 0x40).chr
}.gsub(/[\x80-\xff]/n) { |c|
"<%02X>" % c.ord