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

Fix vlf-write behaviour for newly created file.

This commit is contained in:
Andrey Kotlarski 2013-12-11 13:07:51 +02:00
parent 2aea17ab38
commit 88924f9c05

34
vlf.el
View File

@ -919,18 +919,30 @@ If changing size of chunk, shift remaining file content."
(or (verify-visited-file-modtime (current-buffer)) (or (verify-visited-file-modtime (current-buffer))
(y-or-n-p "File has changed since visited or saved. \ (y-or-n-p "File has changed since visited or saved. \
Save anyway? "))) Save anyway? ")))
(let ((pos (point)) (let* ((pos (point))
(size-change (- vlf-end-pos vlf-start-pos (region-length (length (encode-coding-region
(length (encode-coding-region
(point-min) (point-max) (point-min) (point-max)
buffer-file-coding-system t))))) buffer-file-coding-system t)))
(cond ((zerop size-change) (size-change (- vlf-end-pos vlf-start-pos region-length)))
(write-region nil nil buffer-file-name vlf-start-pos t)) (if (or (zerop size-change) (zerop vlf-file-size))
((< 0 size-change) (progn
(vlf-file-shift-back size-change)) (write-region nil nil buffer-file-name vlf-start-pos t)
(t (vlf-file-shift-forward (- size-change)))) (when (zerop vlf-file-size) ;new file
(vlf-move-to-chunk-2 vlf-start-pos vlf-end-pos) (setq vlf-file-size region-length
(goto-char pos))) vlf-end-pos region-length
vlf-start-pos 1)
(vlf-update-buffer-name)))
(if (< 0 size-change)
(vlf-file-shift-back size-change)
(vlf-file-shift-forward (- size-change)))
(vlf-verify-size)
(vlf-move-to-chunk-2 vlf-start-pos
(if (< (- vlf-end-pos vlf-start-pos)
vlf-batch-size)
(+ vlf-start-pos vlf-batch-size)
vlf-end-pos))
(vlf-update-buffer-name)
(goto-char pos))))
t) t)
(defun vlf-file-shift-back (size-change) (defun vlf-file-shift-back (size-change)