1
0
mirror of https://github.com/m00natic/vlfi.git synced 2025-01-18 20:10:47 +00:00

Reduce scope of vlf-with-undo-disabled usages.

This commit is contained in:
Andrey Kotlarski 2013-12-04 14:40:07 +02:00
parent 177c680288
commit 28646fbfee

76
vlf.el
View File

@ -109,8 +109,10 @@
vlf-file-size)))) vlf-file-size))))
(remove-hook 'write-file-functions 'vlf-write t) (remove-hook 'write-file-functions 'vlf-write t)
(let ((pos (+ vlf-start-pos (position-bytes (point))))) (let ((pos (+ vlf-start-pos (position-bytes (point)))))
(erase-buffer) (vlf-with-undo-disabled
(insert-file-contents buffer-file-name) (erase-buffer)
(insert-file-contents buffer-file-name))
(set-visited-file-modtime)
(set-buffer-modified-p nil) (set-buffer-modified-p nil)
(goto-char (byte-to-position pos))) (goto-char (byte-to-position pos)))
(rename-buffer (file-name-nondirectory buffer-file-name) t)))) (rename-buffer (file-name-nondirectory buffer-file-name) t))))
@ -401,22 +403,22 @@ Return t if move hasn't been canceled."
(defun vlf-move-to-chunk-2 (start end) (defun vlf-move-to-chunk-2 (start end)
"Unconditionally move to chunk determined by START END." "Unconditionally move to chunk determined by START END."
(vlf-with-undo-disabled (setq vlf-start-pos (max 0 start)
(setq vlf-start-pos (max 0 start) vlf-end-pos (min end vlf-file-size))
vlf-end-pos (min end vlf-file-size)) (let ((inhibit-read-only t)
(let ((inhibit-read-only t) (pos (position-bytes (point))))
(pos (position-bytes (point)))) (vlf-with-undo-disabled
(erase-buffer) (erase-buffer)
(insert-file-contents buffer-file-name nil (insert-file-contents buffer-file-name nil
vlf-start-pos vlf-end-pos) vlf-start-pos vlf-end-pos)
(let ((shifts (vlf-adjust-chunk vlf-start-pos vlf-end-pos t (let ((shifts (vlf-adjust-chunk vlf-start-pos vlf-end-pos t
t))) t)))
(setq vlf-start-pos (- vlf-start-pos (car shifts)) (setq vlf-start-pos (- vlf-start-pos (car shifts))
vlf-end-pos (+ vlf-end-pos (cdr shifts))) vlf-end-pos (+ vlf-end-pos (cdr shifts)))
(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)
(set-visited-file-modtime))) (set-visited-file-modtime))
(defun vlf-adjust-chunk (start end &optional adjust-start adjust-end (defun vlf-adjust-chunk (start end &optional adjust-start adjust-end
position) position)
@ -886,12 +888,12 @@ Save anyway? ")))
(defun vlf-file-shift-back (size-change) (defun vlf-file-shift-back (size-change)
"Shift file contents SIZE-CHANGE bytes back." "Shift file contents SIZE-CHANGE bytes back."
(write-region nil nil buffer-file-name vlf-start-pos t) (write-region nil nil buffer-file-name vlf-start-pos t)
(vlf-with-undo-disabled (let ((read-start-pos vlf-end-pos)
(let ((read-start-pos vlf-end-pos) (coding-system-for-write 'no-conversion)
(coding-system-for-write 'no-conversion) (reporter (make-progress-reporter "Adjusting file content..."
(reporter (make-progress-reporter "Adjusting file content..." vlf-end-pos
vlf-end-pos vlf-file-size)))
vlf-file-size))) (vlf-with-undo-disabled
(while (vlf-shift-batch read-start-pos (- read-start-pos (while (vlf-shift-batch read-start-pos (- read-start-pos
size-change)) size-change))
(setq read-start-pos (+ read-start-pos vlf-batch-size)) (setq read-start-pos (+ read-start-pos vlf-batch-size))
@ -899,10 +901,10 @@ Save anyway? ")))
;; pad end with space ;; pad end with space
(erase-buffer) (erase-buffer)
(vlf-verify-size) (vlf-verify-size)
(insert-char 32 size-change) (insert-char 32 size-change))
(write-region nil nil buffer-file-name (- vlf-file-size (write-region nil nil buffer-file-name (- vlf-file-size
size-change) t) size-change) t)
(progress-reporter-done reporter)))) (progress-reporter-done reporter)))
(defun vlf-shift-batch (read-pos write-pos) (defun vlf-shift-batch (read-pos write-pos)
"Read `vlf-batch-size' bytes from READ-POS and write them \ "Read `vlf-batch-size' bytes from READ-POS and write them \
@ -919,13 +921,13 @@ back at WRITE-POS. Return nil if EOF is reached, t otherwise."
(defun vlf-file-shift-forward (size-change) (defun vlf-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."
(vlf-with-undo-disabled (let ((read-size (max (/ vlf-batch-size 2) size-change))
(let ((read-size (max (/ vlf-batch-size 2) size-change)) (read-pos vlf-end-pos)
(read-pos vlf-end-pos) (write-pos vlf-start-pos)
(write-pos vlf-start-pos) (reporter (make-progress-reporter "Adjusting file content..."
(reporter (make-progress-reporter "Adjusting file content..." vlf-start-pos
vlf-start-pos vlf-file-size)))
vlf-file-size))) (vlf-with-undo-disabled
(when (vlf-shift-batches read-size read-pos write-pos t) (when (vlf-shift-batches read-size read-pos write-pos t)
(setq write-pos (+ read-pos size-change) (setq write-pos (+ read-pos size-change)
read-pos (+ read-pos read-size)) read-pos (+ read-pos read-size))
@ -934,8 +936,8 @@ Done by saving content up front and then writing previous batch."
(while (vlf-shift-batches read-size read-pos write-pos nil) (while (vlf-shift-batches read-size read-pos write-pos nil)
(setq write-pos (+ read-pos size-change) (setq write-pos (+ read-pos size-change)
read-pos (+ read-pos read-size)) read-pos (+ read-pos read-size))
(progress-reporter-update reporter write-pos)))) (progress-reporter-update reporter write-pos)))))
(progress-reporter-done reporter)))) (progress-reporter-done reporter)))
(defun vlf-shift-batches (read-size read-pos write-pos hide-read) (defun vlf-shift-batches (read-size read-pos write-pos hide-read)
"Append READ-SIZE bytes of file starting at READ-POS. "Append READ-SIZE bytes of file starting at READ-POS.