mirror of
https://github.com/m00natic/vlfi.git
synced 2025-01-31 02:00:47 +00:00
Don't use temporary buffer when adjusting expanded file content.
This commit is contained in:
parent
1589cf9736
commit
b34bd2e5fb
80
vlfi.el
80
vlfi.el
@ -606,56 +606,46 @@ back at WRITE-POS. Return nil if EOF is reached, t otherwise."
|
|||||||
(defun vlfi-file-shift-forward (size-change)
|
(defun vlfi-file-shift-forward (size-change)
|
||||||
"Shift file contents SIZE-CHANGE bytes forward.
|
"Shift file contents SIZE-CHANGE bytes forward.
|
||||||
Done by saving content up front and then writing previous batch."
|
Done by saving content up front and then writing previous batch."
|
||||||
(let ((vlfi-buffer (current-buffer))
|
(buffer-disable-undo)
|
||||||
(temp-buffer (generate-new-buffer (concat " "
|
(let ((size (+ vlfi-batch-size size-change))
|
||||||
(buffer-name))))
|
(read-pos vlfi-end-pos)
|
||||||
(coding-system-for-write 'no-conversion))
|
(write-pos vlfi-start-pos)
|
||||||
(let ((file buffer-file-name))
|
(reporter (make-progress-reporter "Adjusting file content..."
|
||||||
(set-buffer temp-buffer)
|
vlfi-start-pos
|
||||||
(setq buffer-file-name file)
|
vlfi-file-size)))
|
||||||
(buffer-disable-undo))
|
(when (vlfi-shift-batches size read-pos write-pos t)
|
||||||
(set-buffer vlfi-buffer)
|
(setq write-pos (+ read-pos size-change)
|
||||||
(buffer-disable-undo)
|
read-pos (+ read-pos size))
|
||||||
(let ((read-buffer temp-buffer)
|
(progress-reporter-update reporter write-pos)
|
||||||
(write-buffer vlfi-buffer)
|
(let ((coding-system-for-write 'no-conversion))
|
||||||
(size (+ vlfi-batch-size size-change))
|
(while (vlfi-shift-batches size read-pos write-pos nil)
|
||||||
(read-pos vlfi-end-pos)
|
(setq write-pos (+ read-pos size-change)
|
||||||
(write-pos vlfi-start-pos)
|
read-pos (+ read-pos size))
|
||||||
swap-buffer
|
(progress-reporter-update reporter write-pos))))
|
||||||
(reporter (make-progress-reporter
|
(progress-reporter-done reporter)))
|
||||||
"Adjusting file content..."
|
|
||||||
vlfi-start-pos vlfi-file-size)))
|
|
||||||
(while (vlfi-shift-batches size read-buffer read-pos
|
|
||||||
write-buffer write-pos)
|
|
||||||
(setq swap-buffer read-buffer
|
|
||||||
read-buffer write-buffer
|
|
||||||
write-buffer swap-buffer
|
|
||||||
write-pos (+ read-pos size-change)
|
|
||||||
read-pos (+ read-pos size))
|
|
||||||
(progress-reporter-update reporter write-pos))
|
|
||||||
(progress-reporter-done reporter))
|
|
||||||
(set-buffer temp-buffer)
|
|
||||||
(set-buffer-modified-p nil)
|
|
||||||
(kill-buffer temp-buffer)
|
|
||||||
(set-buffer vlfi-buffer)))
|
|
||||||
|
|
||||||
(defun vlfi-shift-batches (size read-buffer read-pos
|
(defun vlfi-shift-batches (size read-pos write-pos hide-read)
|
||||||
write-buffer write-pos)
|
"Append SIZE bytes of file starting at READ-POS.
|
||||||
"Read SIZE bytes in READ-BUFFER starting from READ-POS.
|
Then write initial buffer content to file at WRITE-POS.
|
||||||
Then write contents of WRITE-BUFFER to buffer file at WRITE-POS.
|
If HIDE-READ is non nil, temporarily hide literal read content.
|
||||||
Return nil if EOF is reached, t otherwise."
|
Return nil if EOF is reached, t otherwise."
|
||||||
(let* ((file-size (vlfi-get-file-size buffer-file-name))
|
(or (verify-visited-file-modtime (current-buffer))
|
||||||
(read-more (< read-pos file-size)))
|
(setq vlfi-file-size (vlfi-get-file-size buffer-file-name)))
|
||||||
|
(let ((read-more (< read-pos vlfi-file-size))
|
||||||
|
(start-write-pos (point-min))
|
||||||
|
(end-write-pos (point-max)))
|
||||||
(when read-more
|
(when read-more
|
||||||
;; read
|
(goto-char end-write-pos)
|
||||||
(set-buffer read-buffer)
|
|
||||||
(erase-buffer)
|
|
||||||
(insert-file-contents-literally buffer-file-name nil read-pos
|
(insert-file-contents-literally buffer-file-name nil read-pos
|
||||||
(min file-size (+ read-pos
|
(min vlfi-file-size (+ read-pos
|
||||||
size))))
|
size))))
|
||||||
;; write
|
;; write
|
||||||
(set-buffer write-buffer)
|
(if hide-read ; hide literal region if user has to choose encoding
|
||||||
(write-region nil nil buffer-file-name write-pos 0)
|
(narrow-to-region start-write-pos end-write-pos))
|
||||||
|
(write-region start-write-pos end-write-pos
|
||||||
|
buffer-file-name write-pos 0)
|
||||||
|
(delete-region start-write-pos end-write-pos)
|
||||||
|
(if hide-read (widen))
|
||||||
read-more))
|
read-more))
|
||||||
|
|
||||||
(provide 'vlfi)
|
(provide 'vlfi)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user