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