[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/vlf 4f99eaa 183/310: Fixes to tiny chunk moves.
From: |
Stefan Monnier |
Subject: |
[elpa] externals/vlf 4f99eaa 183/310: Fixes to tiny chunk moves. |
Date: |
Sat, 28 Nov 2020 00:33:11 -0500 (EST) |
branch: externals/vlf
commit 4f99eaa5e70626757d6a7a5f613da4fa250456e3
Author: Andrey Kotlarski <m00naticus@gmail.com>
Commit: Andrey Kotlarski <m00naticus@gmail.com>
Fixes to tiny chunk moves.
---
vlf.el | 159 ++++++++++++++++++++++++-----------------------------------------
1 file changed, 59 insertions(+), 100 deletions(-)
diff --git a/vlf.el b/vlf.el
index e0feecf..1baea7a 100644
--- a/vlf.el
+++ b/vlf.el
@@ -561,9 +561,11 @@ bytes added to the end."
(setq shift-start (vlf-adjust-start start end position
adjust-end)
start (- start shift-start))
- (vlf-insert-content-safe start end position))
+ (setq shift-end (vlf-insert-content-safe start end position)
+ end (+ end shift-end)))
(if adjust-end
- (setq shift-end (vlf-adjust-end start end position)))
+ (setq shift-end (+ shift-end
+ (vlf-adjust-end start end position))))
(cons shift-start shift-end)))
(defun vlf-adjust-start (start end position adjust-end)
@@ -571,29 +573,26 @@ bytes added to the end."
be properly decoded. Use buffer POSITION as start.
ADJUST-END is non-nil if end would be adjusted later.
Return number of bytes moved back for proper decoding."
- (let* ((shift 0)
- (min-end (min end (+ start vlf-min-chunk-size)))
+ (let* ((min-end (min end (+ start vlf-min-chunk-size)))
(chunk-size (- min-end start))
- (strict (and (not adjust-end) (= min-end end))))
- (vlf-insert-content-safe start min-end position)
+ (shift (vlf-insert-content-safe start min-end position t)))
+ (setq start (+ start shift))
(while (and (not (zerop start))
(< shift 3)
- (or (= position (point-max))
- (let ((diff (- chunk-size
- (length
- (encode-coding-region
- position (point-max)
- buffer-file-coding-system t)))))
- (and (not (zerop diff))
- (cond (strict t)
- (vlf-partial-decode-shown
- (or (< diff -3) (< 0 diff)))
- (t (or (< diff 0) (< 3 diff))))))))
+ (let ((diff (- chunk-size
+ (length
+ (encode-coding-region
+ position (point-max)
+ buffer-file-coding-system t)))))
+ (cond ((not adjust-end) (not (zerop diff)))
+ (vlf-partial-decode-shown
+ (or (< diff -3) (< 0 diff)))
+ (t (or (< diff 0) (< 3 diff))))))
(setq shift (1+ shift)
start (1- start)
chunk-size (1+ chunk-size))
(delete-region position (point-max))
- (vlf-insert-content-safe start min-end position))
+ (insert-file-contents buffer-file-name nil start min-end))
(unless (= min-end end)
(delete-region position (point-max))
(insert-file-contents buffer-file-name nil start end))
@@ -603,93 +602,53 @@ Return number of bytes moved back for proper decoding."
"Adjust chunk end at absolute START to END till content can be\
properly decoded starting at POSITION.
Return number of bytes added for proper decoding."
- (let ((shift 0)
- (new-pos (max position (- (point-max) vlf-min-chunk-size))))
- (if (< position new-pos)
- (setq start (+ start (length (encode-coding-region
- position new-pos
- buffer-file-coding-system t)))
- position new-pos))
+ (let ((shift 0))
(if vlf-partial-decode-shown
- (let ((chunk-size (- end start)))
- (goto-char (point-max))
- (while (and (< end vlf-file-size)
- (< shift 3)
- (or (= position (point-max))
- (if vlf-partial-decode-shown
- (eq (char-charset (preceding-char))
- 'eight-bit))
- (/= chunk-size
- (length (encode-coding-region
- position (point-max)
- buffer-file-coding-system
- t)))))
- (setq shift (1+ shift)
- end (1+ end)
- chunk-size (1+ chunk-size))
- (delete-region position (point-max))
- (vlf-insert-content-safe start end position))))
+ (let ((new-pos (max position
+ (- (point-max) vlf-min-chunk-size))))
+ (if (< position new-pos)
+ (setq start (+ start (length (encode-coding-region
+ position new-pos
+ buffer-file-coding-system
+ t)))
+ position new-pos))))
+ (let ((chunk-size (- end start)))
+ (goto-char (point-max))
+ (while (and (< shift 3)
+ (< end vlf-file-size)
+ (or (eq (char-charset (preceding-char)) 'eight-bit)
+ (/= chunk-size
+ (length (encode-coding-region
+ position (point-max)
+ buffer-file-coding-system t)))))
+ (setq shift (1+ shift)
+ end (1+ end)
+ chunk-size (1+ chunk-size))
+ (delete-region position (point-max))
+ (insert-file-contents buffer-file-name nil start end)
+ (goto-char (point-max))))
shift))
-(defun vlf-insert-content-safe (start end position)
+(defun vlf-insert-content-safe (start end position &optional shift-start)
"Insert file content from absolute START to END of file at\
-POSITION. Clean up if no characters are inserted."
+POSITION. Adjust start if SHIFT-START is non nil, end otherwise.
+Clean up if no characters are inserted."
(goto-char position)
- (let ((tiny (and (not vlf-partial-decode-shown)
- (< (- end start) 4))))
- (if tiny (insert "|"))
- (cond ((zerop (cadr (insert-file-contents buffer-file-name
- nil start end)))
- (delete-region position (point-max)))
- (tiny (delete-region position (1+ position))))))
-
-(defun vlf-adjust-chunk (start end &optional adjust-start adjust-end
- position)
- "Adjust chunk at absolute START to END till content can be\
-properly decoded. ADJUST-START determines if trying to prepend bytes\
- to the beginning, ADJUST-END - append to the end.
-Use buffer POSITION as start if given.
-Return number of bytes moved back for proper decoding and number of
-bytes added to the end."
- (if position (goto-char position))
- (insert-file-contents buffer-file-name nil start end)
- (let ((shift-start 0)
- (shift-end 0))
- (if adjust-start
- (let ((position (or position (point-min)))
- (chunk-size (- end start)))
- (while (and (not (zerop start))
- (< shift-start 4)
- (< 4 (abs (- chunk-size
- (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))
- (delete-region position (point-max))
- (goto-char position)
- (insert-file-contents buffer-file-name nil start end))))
- (if adjust-end
- (cond ((vlf-partial-decode-shown-p) ;remove raw bytes from end
- (goto-char (point-max))
- (while (eq (char-charset (preceding-char)) 'eight-bit)
- (setq shift-end (1- shift-end))
- (delete-char -1)))
- ((< end vlf-file-size) ;add bytes until new character is
displayed
- (let ((position (or position (point-min)))
- (expected-size (buffer-size)))
- (while (and (progn
- (setq shift-end (1+ shift-end)
- end (1+ end))
- (delete-region position (point-max))
- (goto-char position)
- (insert-file-contents buffer-file-name
- nil start end)
- (< end vlf-file-size))
- (= expected-size (buffer-size))))))))
- (cons shift-start shift-end)))
+ (let ((shift 0))
+ (while (and (< shift 3)
+ (zerop (cadr (insert-file-contents buffer-file-name
+ nil start end)))
+ (if shift-start
+ (not (zerop start))
+ (< end vlf-file-size)))
+ ;; TODO: this seems like regression after Emacs 24.3
+ (message "Buffer content may be broken")
+ (setq shift (1+ shift))
+ (if shift-start
+ (setq start (1- start))
+ (setq end (1+ end)))
+ (delete-region position (point-max)))
+ shift))
(defun vlf-partial-decode-shown-p ()
"Determine if partial decode codes are displayed.
- [elpa] externals/vlf 290c4ac 176/310: Fix save with adjustment., (continued)
- [elpa] externals/vlf 290c4ac 176/310: Fix save with adjustment., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf d88080f 178/310: Don't apply VLF over ebrowse and TAGS databases., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 4d82c78 197/310: - don't nullify default buffer coding system, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 117935d 200/310: Add progress reporter when searching for difference., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf bfcbfd3 132/310: Make error message more descriptive., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 28646fb 148/310: Reduce scope of vlf-with-undo-disabled usages., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 72fec35 162/310: Update README and bump version., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 65b4d74 170/310: Refactor vlf-write., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 099adab 171/310: Fix abort-if-file-too-large advice not to activate VLF in case of empty, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf c58d0d8 180/310: Shift buffer-undo-list elements when chunk beginning moves., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 4f99eaa 183/310: Fixes to tiny chunk moves.,
Stefan Monnier <=
- [elpa] externals/vlf 7794b2c 185/310: Merge branch 'shift-undo' into chunk-move, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf d7766f2 209/310: Update documentation and mark autoloaded functions as interactive., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 5d30eb4 206/310: Use single ediff pass to adjust borders. Protect against user, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf ffac697 217/310: Keep undo list after occur or unsuccessful line search., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf b05255b 220/310: Add hooks to run around chunk moves and batch operations. Don't err, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 557d751 236/310: Be more precise on restoring hexl-mode after chunk update has been, Stefan Monnier, 2020/11/28
- [elpa] externals/vlf ece554a 231/310: Wording., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf 069b2f5 240/310: Replace operations with respective vlf-tune wrappers., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf fb05030 241/310: Add basic tune strategies., Stefan Monnier, 2020/11/28
- [elpa] externals/vlf e18a05b 247/310: Add linear search for tuning and prefer smaller batches., Stefan Monnier, 2020/11/28