mirror of
https://github.com/m00natic/vlfi.git
synced 2025-04-18 16:50:19 +01:00
Shift buffer-undo-list elements when chunk beginning moves.
This commit is contained in:
parent
386d85656c
commit
c58d0d84ff
68
vlf.el
68
vlf.el
@ -113,6 +113,67 @@ continuously recenter.")
|
|||||||
(unwind-protect (progn ,@body)
|
(unwind-protect (progn ,@body)
|
||||||
(setq buffer-undo-list undo-list))))
|
(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)
|
||||||
|
(let (undo-list)
|
||||||
|
(setq buffer-undo-list
|
||||||
|
(catch 'end
|
||||||
|
(dolist (el buffer-undo-list)
|
||||||
|
(push
|
||||||
|
(cond
|
||||||
|
((null el) nil)
|
||||||
|
((numberp el) (let ((pos (+ el n)))
|
||||||
|
(if (< n 0)
|
||||||
|
(throw 'end undo-list)
|
||||||
|
pos)))
|
||||||
|
(t (let ((head (car el)))
|
||||||
|
(cond ((numberp head)
|
||||||
|
(let ((beg (+ head n)))
|
||||||
|
(if (< beg 0)
|
||||||
|
(throw 'end undo-list)
|
||||||
|
(cons beg (+ (cdr el) n)))))
|
||||||
|
((stringp head)
|
||||||
|
(let* ((pos (cdr el))
|
||||||
|
(positive (< 0 pos))
|
||||||
|
(new (+ (abs pos) n)))
|
||||||
|
(if (< new 0)
|
||||||
|
(throw 'end undo-list)
|
||||||
|
(cons head (if positive
|
||||||
|
new
|
||||||
|
(- new))))))
|
||||||
|
((null head)
|
||||||
|
(let ((beg (+ (nth 3 el) n)))
|
||||||
|
(if (< beg 0)
|
||||||
|
(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 0)
|
||||||
|
(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))
|
||||||
|
undo-list)))))
|
||||||
|
|
||||||
(define-minor-mode vlf-mode
|
(define-minor-mode vlf-mode
|
||||||
"Mode to browse large files in."
|
"Mode to browse large files in."
|
||||||
:lighter " VLF"
|
:lighter " VLF"
|
||||||
@ -491,7 +552,8 @@ Return t if move hasn't been canceled."
|
|||||||
t))))
|
t))))
|
||||||
(setq start (+ vlf-start-pos del-len))
|
(setq start (+ vlf-start-pos del-len))
|
||||||
(vlf-with-undo-disabled
|
(vlf-with-undo-disabled
|
||||||
(delete-region (point-min) del-pos))))
|
(delete-region (point-min) del-pos))
|
||||||
|
(vlf-shift-undo-list (- del-len))))
|
||||||
((< start vlf-start-pos)
|
((< start vlf-start-pos)
|
||||||
(let ((edit-end-pos (point-max)))
|
(let ((edit-end-pos (point-max)))
|
||||||
(goto-char edit-end-pos)
|
(goto-char edit-end-pos)
|
||||||
@ -505,7 +567,8 @@ Return t if move hasn't been canceled."
|
|||||||
edit-end-pos)))
|
edit-end-pos)))
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(insert (delete-and-extract-region edit-end-pos
|
(insert (delete-and-extract-region edit-end-pos
|
||||||
(point-max)))))))
|
(point-max))))
|
||||||
|
(vlf-shift-undo-list (- (point-max) edit-end-pos)))))
|
||||||
(setq start (- start shift-start))
|
(setq start (- start shift-start))
|
||||||
(goto-char (or (byte-to-position (- pos start))
|
(goto-char (or (byte-to-position (- pos start))
|
||||||
(byte-to-position (- pos vlf-start-pos))
|
(byte-to-position (- pos vlf-start-pos))
|
||||||
@ -532,6 +595,7 @@ Return t if move hasn't been canceled."
|
|||||||
(goto-char (or (byte-to-position (+ pos (car shifts)))
|
(goto-char (or (byte-to-position (+ pos (car shifts)))
|
||||||
(point-max))))))
|
(point-max))))))
|
||||||
(set-buffer-modified-p nil)
|
(set-buffer-modified-p nil)
|
||||||
|
(setq buffer-undo-list nil)
|
||||||
(set-visited-file-modtime))
|
(set-visited-file-modtime))
|
||||||
|
|
||||||
(defun vlf-adjust-chunk (start end &optional adjust-start adjust-end
|
(defun vlf-adjust-chunk (start end &optional adjust-start adjust-end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user