mirror of
https://github.com/m00natic/vlfi.git
synced 2025-01-18 20:10:47 +00:00
Make saving with change of size correct.
This commit is contained in:
parent
5405a30de4
commit
06108220e2
32
vlfi.el
32
vlfi.el
@ -399,14 +399,32 @@ successful. Return nil if nothing found."
|
||||
or \\[vlfi-discard-edit] to discard changes.")))
|
||||
|
||||
(defun vlfi-write ()
|
||||
"Write current chunk to file. May overwrite existing content."
|
||||
"Write current chunk to file.
|
||||
If changing size of chunk, may load the remaining part of file first."
|
||||
(interactive)
|
||||
(when (or (= (buffer-size) (- vlfi-end-pos vlfi-start-pos))
|
||||
(y-or-n-p "Changed size of original chunk. \
|
||||
End of chunk will be garbled. Continue? "))
|
||||
(write-region nil nil buffer-file-name vlfi-start-pos)
|
||||
(vlfi-move-to-chunk vlfi-start-pos vlfi-end-pos)
|
||||
(vlfi-mode))
|
||||
(let ((size-change (- vlfi-end-pos vlfi-start-pos (buffer-size))))
|
||||
(cond ((zerop size-change)
|
||||
(write-region nil nil buffer-file-name vlfi-start-pos t)
|
||||
(vlfi-move-to-chunk vlfi-start-pos vlfi-end-pos)
|
||||
(vlfi-mode))
|
||||
((y-or-n-p "Changed size of original chunk. \
|
||||
Remaining part of the file has to be loaded. Continue? ")
|
||||
(let ((pos (point)))
|
||||
(goto-char (point-max))
|
||||
(setq vlfi-file-size
|
||||
(nth 7 (file-attributes buffer-file-name)))
|
||||
(let ((load-reporter (make-progress-reporter
|
||||
"Loading rest of the file")))
|
||||
(insert-file-contents buffer-file-name nil
|
||||
vlfi-end-pos vlfi-file-size)
|
||||
(when (< 0 size-change) ; pad with empty characters
|
||||
(goto-char (point-max))
|
||||
(insert-char 32 size-change))
|
||||
(progress-reporter-done load-reporter))
|
||||
(write-region nil nil buffer-file-name vlfi-start-pos t)
|
||||
(vlfi-move-to-chunk vlfi-start-pos vlfi-end-pos)
|
||||
(goto-char pos))
|
||||
(vlfi-mode))))
|
||||
t)
|
||||
|
||||
(defun vlfi-discard-edit ()
|
||||
|
Loading…
x
Reference in New Issue
Block a user