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

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

[elpa] externals/vlf 7794b2c 185/310: Merge branch 'shift-undo' into chu


From: Stefan Monnier
Subject: [elpa] externals/vlf 7794b2c 185/310: Merge branch 'shift-undo' into chunk-move
Date: Sat, 28 Nov 2020 00:33:12 -0500 (EST)

branch: externals/vlf
commit 7794b2cab6b1b700cc6351be881d96cad46020da
Merge: 161a4ec 2470fc0
Author: Andrey Kotlarski <m00naticus@gmail.com>
Commit: Andrey Kotlarski <m00naticus@gmail.com>

    Merge branch 'shift-undo' into chunk-move
    
    Conflicts:
        vlf.el
---
 vlf.el | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 67 insertions(+), 2 deletions(-)

diff --git a/vlf.el b/vlf.el
index 3a79c90..89231d5 100644
--- a/vlf.el
+++ b/vlf.el
@@ -123,6 +123,68 @@ continuously recenter.")
      (unwind-protect (progn ,@body)
        (setq buffer-undo-list undo-list))))
 
+(defun vlf-shift-undo-list (n)
+  "Shift undo list element regions by N."
+  (or (eq buffer-undo-list t)
+      (setq buffer-undo-list
+            (nreverse
+             (let ((min (point-min))
+                   undo-list)
+               (catch 'end
+                 (dolist (el buffer-undo-list undo-list)
+                   (push
+                    (cond
+                     ((null el) nil)
+                     ((numberp el) (let ((pos (+ el n)))
+                                     (if (< pos min)
+                                         (throw 'end undo-list)
+                                       pos)))
+                     (t (let ((head (car el)))
+                          (cond ((numberp head)
+                                 (let ((beg (+ head n)))
+                                   (if (< beg min)
+                                       (throw 'end undo-list)
+                                     (cons beg (+ (cdr el) n)))))
+                                ((stringp head)
+                                 (let* ((pos (cdr el))
+                                        (positive (< 0 pos))
+                                        (new (+ (abs pos) n)))
+                                   (if (< new min)
+                                       (throw 'end undo-list)
+                                     (cons head (if positive
+                                                    new
+                                                  (- new))))))
+                                ((null head)
+                                 (let ((beg (+ (nth 3 el) n)))
+                                   (if (< beg min)
+                                       (throw 'end undo-list)
+                                     (cons
+                                      nil
+                                      (cons
+                                       (cadr el)
+                                       (cons
+                                        (nth 2 el)
+                                        (cons beg
+                                              (+ (cddr
+                                                  (cddr el)) n))))))))
+                                ((and (eq head 'apply)
+                                      (numberp (cadr el)))
+                                 (let ((beg (+ (nth 2 el) n)))
+                                   (if (< beg min)
+                                       (throw 'end undo-list)
+                                     (cons
+                                      'apply
+                                      (cons
+                                       (cadr el)
+                                       (cons
+                                        beg
+                                        (cons
+                                         (+ (nth 3 el) n)
+                                         (cons (nth 4 el)
+                                               (cdr (last el))))))))))
+                                (t el)))))
+                    undo-list))))))))
+
 (define-minor-mode vlf-mode
   "Mode to browse large files in."
   :lighter " VLF"
@@ -507,7 +569,8 @@ bytes added to the end."
                                           t))))
                    (setq start (+ vlf-start-pos del-len))
                    (vlf-with-undo-disabled
-                    (delete-region (point-min) del-pos))))
+                    (delete-region (point-min) del-pos))
+                   (vlf-shift-undo-list (- 1 del-pos))))
                 ((< start vlf-start-pos)
                  (if (and (not vlf-partial-decode-shown)
                           (< (- vlf-start-pos start) 4))
@@ -519,7 +582,8 @@ bytes added to the end."
                                               t nil edit-end-pos)))
                       (goto-char (point-min))
                       (insert (delete-and-extract-region
-                               edit-end-pos (point-max))))))))
+                               edit-end-pos (point-max))))
+                     (vlf-shift-undo-list (- (point-max) edit-end-pos))))))
           (setq start (- start shift-start))
           (goto-char (or (byte-to-position (- pos start))
                          (byte-to-position (- pos vlf-start-pos))
@@ -547,6 +611,7 @@ bytes added to the end."
        (goto-char (or (byte-to-position (+ pos (car shifts)))
                       (point-max)))))
     (set-buffer-modified-p nil)
+    (setq buffer-undo-list nil)
     (set-visited-file-modtime)
     shifts))
 



reply via email to

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