emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/vlf 4699008 074/310: Make chunk adjusting automatic.


From: Stefan Monnier
Subject: [elpa] externals/vlf 4699008 074/310: Make chunk adjusting automatic.
Date: Sat, 28 Nov 2020 00:32:50 -0500 (EST)

branch: externals/vlf
commit 469900878db4cc3fecf4f94ef4f965d50a0d09b8
Author: Andrey Kotlarski <m00naticus@gmail.com>
Commit: Andrey Kotlarski <m00naticus@gmail.com>

    Make chunk adjusting automatic.
---
 vlfi.el | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/vlfi.el b/vlfi.el
index 3347ee1..9eb4cc7 100644
--- a/vlfi.el
+++ b/vlfi.el
@@ -461,16 +461,22 @@ Search is performed chunk by chunk in `vlfi-batch-size' 
memory."
         (vlfi-move-to-chunk start-pos end-pos)
         (goto-char pos)))))
 
-(defun vlfi-adjust-chunk (bytes)
-  "Adjust chunk beginning by BYTES."
-  (interactive "p")
+(defun vlfi-adjust-chunk ()
+  "Adjust chunk beginning until content can be properly decoded."
+  (interactive)
   (or (zerop vlfi-start-pos)
-      (let ((pos (+ (point) bytes)))
-        (setq vlfi-start-pos (- vlfi-start-pos bytes))
-        (let ((inhibit-read-only t))
-          (erase-buffer)
-          (insert-file-contents buffer-file-name nil
-                                vlfi-start-pos vlfi-end-pos))
+      (let ((pos (point)))
+        (while (/= (- vlfi-end-pos vlfi-start-pos)
+                   (length (encode-coding-region
+                            (point-min) (point-max)
+                            buffer-file-coding-system t)))
+
+          (setq pos (1- pos)
+                vlfi-start-pos (1- vlfi-start-pos))
+          (let ((inhibit-read-only t))
+            (erase-buffer)
+            (insert-file-contents buffer-file-name nil
+                                  vlfi-start-pos vlfi-end-pos)))
         (set-buffer-modified-p nil)
         (goto-char pos))))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]