From 429a8ff01648f72a551dd1ab02ba6348ac2c80d9 Mon Sep 17 00:00:00 2001 From: Andrey Kotlarski Date: Sat, 11 Jan 2014 19:00:00 +0200 Subject: [PATCH] Widen region when measuring encoded content length. --- vlf-base.el | 9 +++++---- vlf-write.el | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/vlf-base.el b/vlf-base.el index 578891f..a2ad0e0 100644 --- a/vlf-base.el +++ b/vlf-base.el @@ -106,6 +106,7 @@ bytes added to the end." "Move to chunk enclosed by START END keeping as much edits if any. Return number of bytes moved back for proper decoding and number of bytes added to the end." + (widen) (let* ((modified (buffer-modified-p)) (start (max 0 start)) (end (min end vlf-file-size)) @@ -133,8 +134,8 @@ bytes added to the end." (inhibit-read-only t)) (cond ((< end edit-end) (let* ((del-pos (1+ (or (byte-to-position - (- end vlf-start-pos)) - 0))) + (- end vlf-start-pos)) + 0))) (del-len (length (encode-coding-region del-pos (point-max) buffer-file-coding-system @@ -303,8 +304,8 @@ Return number of bytes added over expected." (insert-file-contents-literally buffer-file-name nil start end) (let ((coding-system-for-read coding)) (decode-coding-inserted-region position (point-max) - buffer-file-name nil start end)) - (setq buffer-file-coding-system last-coding-system-used))) + buffer-file-name nil start end))) + (setq buffer-file-coding-system last-coding-system-used)) (defun vlf-shift-undo-list (n) "Shift undo list element regions by N." diff --git a/vlf-write.el b/vlf-write.el index f1257d3..7e9d069 100644 --- a/vlf-write.el +++ b/vlf-write.el @@ -44,6 +44,7 @@ Save anyway? ")) buffer-file-truename) vlf-end-pos vlf-file-size) (vlf-update-buffer-name)) + (widen) (let* ((region-length (length (encode-coding-region (point-min) (point-max) buffer-file-coding-system t)))