From 9510c708608beb9b168f5944877501befb3362d1 Mon Sep 17 00:00:00 2001 From: Andrey Kotlarski Date: Mon, 27 Jan 2014 01:16:00 +0200 Subject: [PATCH] Retry decoding when the initial attempt seems wrong. --- vlf-base.el | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/vlf-base.el b/vlf-base.el index 761da5f..c3d64fe 100644 --- a/vlf-base.el +++ b/vlf-base.el @@ -249,6 +249,15 @@ bytes added to the end." (let ((coding-system-for-read coding)) (decode-coding-inserted-region position (point-max) buffer-file-name nil start end))) + (when (eq (detect-coding-region position (min (+ position + vlf-sample-size) + (point-max)) t) + 'no-conversion) + (delete-region position (point-max)) + (insert-file-contents-literally buffer-file-name nil start end) + (let ((coding-system-for-read nil)) + (decode-coding-inserted-region position (point-max) + buffer-file-name nil start end))) (setq buffer-file-coding-system last-coding-system-used)) (defun vlf-adjust-start (start end position adjust-end)