338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
|
# File 'lib/textbringer/buffer.rb', line 338
def revert(enc = nil)
if @file_name.nil?
raise EditorError, "Buffer has no file name"
end
clear
s, mtime = File.open(@file_name,
external_encoding: Encoding::ASCII_8BIT,
binmode: true) { |f|
f.flock(File::LOCK_SH)
[f.read, f.mtime]
}
enc ||= @@detect_encoding_proc.call(s) || Encoding::ASCII_8BIT
s.force_encoding(enc)
unless s.valid_encoding?
enc = Encoding::ASCII_8BIT
s.force_encoding(enc)
end
set_contents(s, enc)
@file_mtime = mtime
@modified = false
end
|