mirror of
https://github.com/m00natic/vlfi.git
synced 2025-02-24 05:48:06 +00:00
Improvements to file saving.
This commit is contained in:
parent
c4f87f9ec7
commit
2525ebf069
55
vlfi.el
55
vlfi.el
@ -400,34 +400,41 @@ Search is performed chunk by chunk in `vlfi-batch-size' memory."
|
|||||||
"Editing: Type \\[vlfi-write] to write chunk \
|
"Editing: Type \\[vlfi-write] to write chunk \
|
||||||
or \\[vlfi-discard-edit] to discard changes.")))
|
or \\[vlfi-discard-edit] to discard changes.")))
|
||||||
|
|
||||||
|
(defun vlfi-write-1 ()
|
||||||
|
"Append current buffer content to `vlfi-start-pos' position in file.
|
||||||
|
Reopen last viewed chunk."
|
||||||
|
(write-region nil nil buffer-file-name vlfi-start-pos t)
|
||||||
|
(vlfi-move-to-chunk vlfi-start-pos vlfi-end-pos)
|
||||||
|
(vlfi-mode))
|
||||||
|
|
||||||
(defun vlfi-write ()
|
(defun vlfi-write ()
|
||||||
"Write current chunk to file.
|
"Write current chunk to file. Always return true to disable save.
|
||||||
If changing size of chunk, may load the remaining part of file first."
|
If changing size of chunk, may load the remaining part of file first."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((size-change (- vlfi-end-pos vlfi-start-pos (buffer-size))))
|
(when (and (derived-mode-p 'vlfi-mode)
|
||||||
(cond ((zerop size-change)
|
(buffer-modified-p))
|
||||||
(write-region nil nil buffer-file-name vlfi-start-pos t)
|
(let ((size-change (- vlfi-end-pos vlfi-start-pos (buffer-size))))
|
||||||
(vlfi-move-to-chunk vlfi-start-pos vlfi-end-pos)
|
(if (zerop size-change)
|
||||||
(vlfi-mode))
|
(vlfi-write-1)
|
||||||
((y-or-n-p "Changed size of original chunk. \
|
(setq vlfi-file-size (nth 7
|
||||||
Remaining part of the file has to be loaded. Continue? ")
|
(file-attributes buffer-file-name)))
|
||||||
(let ((pos (point)))
|
(cond ((= vlfi-file-size vlfi-end-pos)
|
||||||
(goto-char (point-max))
|
(vlfi-write-1))
|
||||||
(setq vlfi-file-size
|
((y-or-n-p (concat "Changed size of original chunk. \
|
||||||
(nth 7 (file-attributes buffer-file-name)))
|
Remaining part of the file ["
|
||||||
(let ((load-reporter (make-progress-reporter
|
(file-size-human-readable
|
||||||
"Loading rest of the file")))
|
(- vlfi-file-size vlfi-end-pos))
|
||||||
(insert-file-contents buffer-file-name nil
|
"] has to be loaded. Continue? "))
|
||||||
vlfi-end-pos vlfi-file-size)
|
(let ((pos (point)))
|
||||||
(when (< 0 size-change) ; pad with empty characters
|
|
||||||
(goto-char (point-max))
|
(goto-char (point-max))
|
||||||
(insert-char 32 size-change))
|
(insert-file-contents buffer-file-name nil
|
||||||
(progress-reporter-done load-reporter))
|
vlfi-end-pos vlfi-file-size)
|
||||||
(write-region nil nil buffer-file-name vlfi-start-pos t)
|
(when (< 0 size-change) ; pad with empty characters
|
||||||
(vlfi-move-to-chunk vlfi-start-pos vlfi-end-pos)
|
(goto-char (point-max))
|
||||||
(goto-char pos))
|
(insert-char 32 size-change))
|
||||||
(vlfi-mode))))
|
(vlfi-write-1)
|
||||||
t)
|
(goto-char pos))))))
|
||||||
|
t))
|
||||||
|
|
||||||
(defun vlfi-discard-edit ()
|
(defun vlfi-discard-edit ()
|
||||||
"Discard edit and refresh chunk from file."
|
"Discard edit and refresh chunk from file."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user