1
0
mirror of https://github.com/m00natic/vlfi.git synced 2025-02-07 13:40:49 +00:00

Revert to using insert-file-contents instead of manual decoding.

This commit is contained in:
Andrey Kotlarski 2014-02-14 02:44:43 +02:00
parent 0199c2468a
commit 924d6b18fa

View File

@ -27,15 +27,12 @@
;;; Code: ;;; Code:
(defgroup vlf nil (defgroup vlf nil "View Large Files in Emacs."
"View Large Files in Emacs." :prefix "vlf-" :group 'files)
:prefix "vlf-"
:group 'files)
(defcustom vlf-batch-size 1024 (defcustom vlf-batch-size 1024
"Defines how large each batch of file data is (in bytes)." "Defines how large each batch of file data is (in bytes)."
:group 'vlf :group 'vlf :type 'integer)
:type 'integer)
(put 'vlf-batch-size 'permanent-local t) (put 'vlf-batch-size 'permanent-local t)
;;; Keep track of file position. ;;; Keep track of file position.
@ -221,13 +218,14 @@ bytes added to the end."
(goto-char (or (byte-to-position (+ pos (car shifts))) (goto-char (or (byte-to-position (+ pos (car shifts)))
(point-max))))) (point-max)))))
(set-buffer-modified-p nil) (set-buffer-modified-p nil)
(setq buffer-undo-list nil) (or (eq buffer-undo-list t)
(setq buffer-undo-list nil))
shifts)) shifts))
(defun vlf-insert-file-contents (start end adjust-start adjust-end (defun vlf-insert-file-contents (start end adjust-start adjust-end
&optional position) &optional position)
"Adjust chunk at absolute START to END till content can be\ "Adjust chunk at absolute START to END till content can be\
properly decoded. ADJUST-START determines if trying to prepend bytes\ properly decoded. ADJUST-START determines if trying to prepend bytes
to the beginning, ADJUST-END - append to the end. to the beginning, ADJUST-END - append to the end.
Use buffer POSITION as start if given. Use buffer POSITION as start if given.
Return number of bytes moved back for proper decoding and number of Return number of bytes moved back for proper decoding and number of
@ -245,7 +243,7 @@ bytes added to the end."
(setq shift-start (vlf-adjust-start start safe-end position (setq shift-start (vlf-adjust-start start safe-end position
adjust-end) adjust-end)
start (- start shift-start)) start (- start shift-start))
(vlf-insert-file-contents-1 start safe-end position)) (vlf-insert-file-contents-1 start safe-end))
(if adjust-end (if adjust-end
(setq shift-end (- (car (vlf-delete-region position start (setq shift-end (- (car (vlf-delete-region position start
safe-end end safe-end end
@ -254,23 +252,9 @@ bytes added to the end."
end))) end)))
(cons shift-start shift-end))) (cons shift-start shift-end)))
(defun vlf-insert-file-contents-1 (start end position) (defun vlf-insert-file-contents-1 (start end)
"Extract decoded file bytes START to END at POSITION." "Extract decoded file bytes START to END."
(let ((coding buffer-file-coding-system)) (insert-file-contents buffer-file-name nil start end))
(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)))
(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) (defun vlf-adjust-start (start end position adjust-end)
"Adjust chunk beginning at absolute START to END till content can\ "Adjust chunk beginning at absolute START to END till content can\
@ -283,8 +267,8 @@ Return number of bytes moved back for proper decoding."
(strict (or (= sample-end vlf-file-size) (strict (or (= sample-end vlf-file-size)
(and (not adjust-end) (= sample-end end)))) (and (not adjust-end) (= sample-end end))))
(shift 0)) (shift 0))
(while (and (progn (vlf-insert-file-contents-1 (while (and (progn (vlf-insert-file-contents-1 safe-start
safe-start sample-end position) sample-end)
(not (zerop safe-start))) (not (zerop safe-start)))
(< shift 3) (< shift 3)
(let ((diff (- chunk-size (let ((diff (- chunk-size
@ -304,7 +288,7 @@ Return number of bytes moved back for proper decoding."
position t 'start))) position t 'start)))
(unless (= sample-end end) (unless (= sample-end end)
(delete-region position (point-max)) (delete-region position (point-max))
(vlf-insert-file-contents-1 safe-start end position)) (vlf-insert-file-contents-1 safe-start end))
(- start safe-start))) (- start safe-start)))
(defun vlf-delete-region (position start end border cut-point from-start (defun vlf-delete-region (position start end border cut-point from-start