[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/vlf 0610822 046/310: Make saving with change of size co
From: |
Stefan Monnier |
Subject: |
[elpa] externals/vlf 0610822 046/310: Make saving with change of size correct. |
Date: |
Sat, 28 Nov 2020 00:32:44 -0500 (EST) |
branch: externals/vlf
commit 06108220e20e381dbcab4dda507d37dfb2b9abf1
Author: Andrey Kotlarski <m00naticus@gmail.com>
Commit: Andrey Kotlarski <m00naticus@gmail.com>
Make saving with change of size correct.
---
vlfi.el | 32 +++++++++++++++++++++++++-------
1 file changed, 25 insertions(+), 7 deletions(-)
diff --git a/vlfi.el b/vlfi.el
index ffa5263..db15580 100644
--- a/vlfi.el
+++ b/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 ()
- [elpa] externals/vlf a3c405f 051/310: Make detection of buffer size change on save more correct when dealing, (continued)
- [elpa] externals/vlf a3c405f 051/310: Make detection of buffer size change on save more correct when dealing, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 7985f0f 052/310: Fix `vlfi-if-file-too-large' to be more tolerable on GNU Emacs 23., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 8637ce5 062/310: Update README and version., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 4cbefde 067/310: Optimize chunk save buffers for multiple insert/erase operations., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 473536e 073/310: Add adjust command for cases where chunk starts with part of multibyte symbol., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 2564c9a 006/310: Plug option for vlf when opening files on package load., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf c0d143b 011/310: Rename vlf to vlfi and update README., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 36411c3 022/310: Enhance search to cover in between chunk boundaries., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 88cf03c 030/310: Interactive change of batch size immediately updates content., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 995a7a0 042/310: Change some VLFI key-bindings not to override special-mode ones., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 0610822 046/310: Make saving with change of size correct.,
Stefan Monnier <=
- [elpa] externals/vlf b52ca6c 063/310: Don't change encoding for edited chunk, leave it to the user in case, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf a31be70 076/310: Update README and bump version., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf ca8ba42 077/310: Fix position handling to correctly deal with multibyte characters., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 5aef3e1 078/310: Update file size changes more lazily., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf ba439de 083/310: Initial generation of vlfi-occur results., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 83eb8a5 080/310: Fixes for GNU Emacs 23., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 70719b0 089/310: Add vlfi-occur-show command for showing match but still staying in, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf a5fec57 090/310: Mostly documentation and commentary added., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf fbc3a37 094/310: Add tip for ability to change major mode and more section hierarchy., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf fd9c258 096/310: Use permanent buffer local write hook and update README., Stefan Monnier, 2020/11/28