[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/vlf 2d71996 125/310: Add end character shift when adjus
From: |
Stefan Monnier |
Subject: |
[elpa] externals/vlf 2d71996 125/310: Add end character shift when adjusting chunk. Apply partial chunk |
Date: |
Sat, 28 Nov 2020 00:33:00 -0500 (EST) |
branch: externals/vlf
commit 2d71996d9e35d6c1465b1f59bb0aa2cd20364bee
Author: Andrey Kotlarski <m00naticus@gmail.com>
Commit: Andrey Kotlarski <m00naticus@gmail.com>
Add end character shift when adjusting chunk. Apply partial chunk
update when buffer is not modified too.
---
vlfi.el | 120 ++++++++++++++++++++++++++++++++++------------------------------
1 file changed, 64 insertions(+), 56 deletions(-)
diff --git a/vlfi.el b/vlfi.el
index f4d60fc..5fc0b84 100644
--- a/vlfi.el
+++ b/vlfi.el
@@ -197,7 +197,7 @@ with the prefix argument DECREASE it is halved."
(format "%s(%s)[%d/%d](%d)"
(file-name-nondirectory buffer-file-name)
(file-size-human-readable vlfi-file-size)
- (/ vlfi-end-pos vlfi-batch-size)
+ (/ (+ vlfi-end-pos 4) vlfi-batch-size)
(/ vlfi-file-size vlfi-batch-size)
vlfi-batch-size))
@@ -302,46 +302,33 @@ When given MINIMAL flag, skip non important operations."
"Move to chunk determined by START END.
When given MINIMAL flag, skip non important operations."
(vlfi-verify-size)
- (if (buffer-modified-p)
- (and (vlfi-move-to-chunk-2 start end)
- (not minimal)
- (vlfi-update-buffer-name))
- (vlfi-move-to-chunk-1 start end)
- (or minimal (vlfi-update-buffer-name))))
+ (and (vlfi-move-to-chunk-1 start end)
+ (not minimal)
+ (vlfi-update-buffer-name)))
(defun vlfi-move-to-chunk-1 (start end)
- "Move to chunk determined by START END."
- (setq vlfi-start-pos (max 0 start)
- vlfi-end-pos (min end vlfi-file-size))
- (let ((inhibit-read-only t)
- (pos (position-bytes (point))))
- (erase-buffer)
- (insert-file-contents buffer-file-name nil
- vlfi-start-pos vlfi-end-pos)
- (let ((shift (vlfi-adjust-chunk vlfi-start-pos vlfi-end-pos)))
- (setq vlfi-start-pos (- vlfi-start-pos shift))
- (goto-char (or (byte-to-position (+ pos shift))
- (point-max)))))
- (set-buffer-modified-p nil)
- (set-visited-file-modtime))
-
-(defun vlfi-move-to-chunk-2 (start end)
- "Move to chunk determined by START END.
+ "Move to chunk determined by START END keeping as much changes.
Return t if move hasn't been canceled."
- (let ((start (max 0 start))
+ (let ((modified (buffer-modified-p))
+ (start (max 0 start))
(end (min end vlfi-file-size))
(edit-end (+ (position-bytes (point-max)) vlfi-start-pos)))
(cond
((and (= start vlfi-start-pos) (= end edit-end))
- nil)
+ (unless modified
+ (vlfi-move-to-chunk-2 start end)
+ t))
((or (<= edit-end start) (<= end vlfi-start-pos))
- (when (y-or-n-p "Buffer modified, are you sure? ") ; full chunk renewal
- (vlfi-move-to-chunk-1 start end)
+ (when (or (not modified)
+ (y-or-n-p "Buffer modified, are you sure? ")) ; full chunk
renewal
+ (vlfi-move-to-chunk-2 start end)
t))
((or (and (<= start vlfi-start-pos) (<= edit-end end))
+ (not modified)
(y-or-n-p "Buffer modified, are you sure? "))
(let ((pos (+ (position-bytes (point)) vlfi-start-pos))
- (shift 0)
+ (shift-start 0)
+ (shift-end 0)
(inhibit-read-only t))
(cond ((< end edit-end)
(delete-region (byte-to-position (- end
@@ -352,7 +339,9 @@ Return t if move hasn't been canceled."
(goto-char edit-end-pos)
(insert-file-contents buffer-file-name nil
vlfi-end-pos end)
- (vlfi-adjust-chunk vlfi-end-pos end edit-end-pos))))
+ (setq shift-end (cdr (vlfi-adjust-chunk
+ vlfi-end-pos end
+ edit-end-pos))))))
(cond ((< vlfi-start-pos start)
(delete-region (point-min) (byte-to-position
(- start vlfi-start-pos))))
@@ -361,46 +350,65 @@ Return t if move hasn't been canceled."
(goto-char edit-end-pos)
(insert-file-contents buffer-file-name nil
start vlfi-start-pos)
- (setq shift (vlfi-adjust-chunk start vlfi-start-pos
- edit-end-pos))
+ (setq shift-start (car
+ (vlfi-adjust-chunk start
+ vlfi-start-pos
+ edit-end-pos)))
(goto-char (point-min))
(insert (delete-and-extract-region edit-end-pos
(point-max))))))
- (setq vlfi-start-pos (- start shift)
- vlfi-end-pos end)
+ (setq vlfi-start-pos (- start shift-start)
+ vlfi-end-pos (- end shift-end))
(goto-char (or (byte-to-position (- pos vlfi-start-pos))
(point-max))))
- (set-visited-file-modtime)
+ (set-buffer-modified-p modified)
t))))
+(defun vlfi-move-to-chunk-2 (start end)
+ "Move to chunk determined by START END."
+ (setq vlfi-start-pos (max 0 start)
+ vlfi-end-pos (min end vlfi-file-size))
+ (let ((inhibit-read-only t)
+ (pos (position-bytes (point))))
+ (erase-buffer)
+ (insert-file-contents buffer-file-name nil
+ vlfi-start-pos vlfi-end-pos)
+ (let ((shifts (vlfi-adjust-chunk vlfi-start-pos vlfi-end-pos)))
+ (setq vlfi-start-pos (- vlfi-start-pos (car shifts))
+ vlfi-end-pos (- vlfi-end-pos (cdr shifts)))
+ (goto-char (or (byte-to-position (+ pos (car shifts)))
+ (point-max)))))
+ (set-buffer-modified-p nil)
+ (set-visited-file-modtime))
+
(defun vlfi-adjust-chunk (start end &optional position)
"Adjust chunk at absolute START till END until content can be \
properly decoded. Use buffer POSITION as start if given.
-Set `vlfi-encode-size' to size of buffer when encoded.
-Return number of bytes moved back for this to happen."
- (let ((update-encode-size (not position))
- (encode-size 0)
- (position (or position (point-min)))
- (shift 0)
+Return number of bytes moved back for proper decoding and number of
+bytes striped from the end character."
+ (let ((position (or position (point-min)))
+ (shift-start 0)
+ (shift-end 0)
(chunk-size (- end start)))
- (while (and (< shift 4)
+ (while (and (not (zerop start))
+ (< shift-start 4)
(< 4 (abs (- chunk-size
- (setq encode-size
- (length (encode-coding-region
- position (point-max)
- buffer-file-coding-system
- t))))))
- (not (zerop start)))
- (setq shift (1+ shift)
+ (length (encode-coding-region
+ position (point-max)
+ buffer-file-coding-system
+ t))))))
+ (setq shift-start (1+ shift-start)
start (1- start)
chunk-size (1+ chunk-size))
- (let ((inhibit-read-only t))
- (delete-region position (point-max))
- (goto-char position)
- (insert-file-contents buffer-file-name nil start end)))
- (if update-encode-size
- (setq vlfi-encode-size encode-size))
- shift))
+ (delete-region position (point-max))
+ (goto-char position)
+ (insert-file-contents buffer-file-name nil start end))
+ (if (< end vlfi-file-size)
+ (let ((point-max (point-max)))
+ (setq shift-end (- (position-bytes point-max)
+ (position-bytes (1- point-max))))
+ (delete-region (1- point-max) point-max))) ;delete last character,
may be incomplete
+ (cons shift-start shift-end)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; search
- [elpa] externals/vlf de1948e 108/310: Merge branch 'master' into chunk-opt2, (continued)
- [elpa] externals/vlf de1948e 108/310: Merge branch 'master' into chunk-opt2, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf c827c3e 110/310: Prevent standard save procedure invocation in case user postpones, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf b943008 113/310: Bump version and update README., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf c1aedbc 116/310: Update README: VLFI is now development version of VLF., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 616d676 114/310: Alters vlfi to respect the default-directory variable when opening, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 3d652fe 103/310: Minor documentation fixes., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 4589c25 112/310: Return to current position after occur ending with quit., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf ce9441f 120/310: Update info as VLFI is merging back to VLF. Bump version., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 7cb0474 122/310: Add forgotten vlfi-encode-size local variable creation., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 02a37c4 123/310: Merge branch 'master' into chunk-opt2, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 2d71996 125/310: Add end character shift when adjusting chunk. Apply partial chunk,
Stefan Monnier <=
- [elpa] externals/vlf 737c1e9 126/310: Remove encode size bookkeeping., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf d1b34dc 127/310: Add autoload cookie for `file-size-human-readable' not to break GNU, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 4c631bc 129/310: Rename vlfi.el to vlf.el., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 17c6612 130/310: Rename anything vlfi -> vlf., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf bc68eed 131/310: Add dummy vlfi.el that urges move to the vlf package., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 025399a 133/310: Merge branch 'master' into keep-edit, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf f34986a 142/310: Update README., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 931ca52 145/310: Stylistic refinements., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 2ac3e7d 146/310: Fix prematurely ending search/occur not to ask for modified buffer, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 0080991 154/310: Fix chunk end adjustment and save for trunk Emacs., Stefan Monnier, 2020/11/28