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

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

[elpa] externals/vlf a3901b8 157/310: Fix deletion when moving to partia


From: Stefan Monnier
Subject: [elpa] externals/vlf a3901b8 157/310: Fix deletion when moving to partially overlapping chunk and enable more
Date: Sat, 28 Nov 2020 00:33:06 -0500 (EST)

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

    Fix deletion when moving to partially overlapping chunk and enable more
    intelligent behaviour in cases of overlapping and modifications.
---
 vlf.el | 35 ++++++++++++++++++++++-------------
 1 file changed, 22 insertions(+), 13 deletions(-)

diff --git a/vlf.el b/vlf.el
index e9f559c..6084fe4 100644
--- a/vlf.el
+++ b/vlf.el
@@ -341,11 +341,8 @@ If same as current chunk is requested, do nothing."
   (unless (and (= start vlf-start-pos)
                (= end vlf-end-pos))
     (vlf-verify-size)
-    (if (buffer-modified-p)
-        (if (vlf-move-to-chunk-1 start end)
-            (or minimal (vlf-update-buffer-name)))
-      (vlf-move-to-chunk-2 start end)
-      (or minimal (vlf-update-buffer-name)))))
+    (if (vlf-move-to-chunk-1 start end)
+        (or minimal (vlf-update-buffer-name)))))
 
 (defun vlf-move-to-chunk-1 (start end)
   "Move to chunk determined by START END keeping as much edits if any.
@@ -362,6 +359,7 @@ Return t if move hasn't been canceled."
      ((or (<= edit-end start) (<= end vlf-start-pos))
       (when (or (not modified)
                 (y-or-n-p "Chunk modified, are you sure? ")) ;full chunk 
renewal
+        (set-buffer-modified-p nil)
         (vlf-move-to-chunk-2 start end)
         t))
      ((or (and (<= start vlf-start-pos) (<= edit-end end))
@@ -372,10 +370,15 @@ Return t if move hasn't been canceled."
             (shift-end 0)
             (inhibit-read-only t))
         (cond ((< end edit-end)
-               (vlf-with-undo-disabled
-                (delete-region (byte-to-position
-                                (1+ (- end vlf-start-pos)))
-                               (point-max))))
+               (let* ((del-pos (1+ (byte-to-position
+                                    (- end vlf-start-pos))))
+                      (del-len (length (encode-coding-region
+                                        del-pos (point-max)
+                                        buffer-file-coding-system
+                                        t))))
+                 (setq end (- vlf-end-pos del-len))
+                 (vlf-with-undo-disabled
+                  (delete-region del-pos (point-max)))))
               ((< edit-end end)
                (let ((edit-end-pos (point-max)))
                  (goto-char edit-end-pos)
@@ -386,9 +389,15 @@ Return t if move hasn't been canceled."
                                         vlf-end-pos end nil t
                                         edit-end-pos)))))))
         (cond ((< vlf-start-pos start)
-               (vlf-with-undo-disabled
-                (delete-region (point-min) (byte-to-position
-                                            (- start vlf-start-pos)))))
+               (let* ((del-pos (1+ (byte-to-position
+                                    (- start vlf-start-pos))))
+                      (del-len (length (encode-coding-region
+                                        (point-min) del-pos
+                                        buffer-file-coding-system
+                                        t))))
+                 (setq start (+ vlf-start-pos del-len))
+                 (vlf-with-undo-disabled
+                  (delete-region (point-min) del-pos))))
               ((< start vlf-start-pos)
                (let ((edit-end-pos (point-max)))
                  (goto-char edit-end-pos)
@@ -876,7 +885,7 @@ in file: %s" total-matches line regexp file)
   "Discard edit and refresh chunk from file."
   (interactive)
   (set-buffer-modified-p nil)
-  (vlf-move-to-chunk vlf-start-pos vlf-end-pos))
+  (vlf-move-to-chunk-2 vlf-start-pos vlf-end-pos))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; saving



reply via email to

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