mirror of
https://github.com/m00natic/vlfi.git
synced 2025-04-18 16:50:19 +01:00
Merge branch 'shift-undo' into chunk-move
Conflicts: vlf.el
This commit is contained in:
commit
7794b2cab6
69
vlf.el
69
vlf.el
@ -123,6 +123,68 @@ 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)
|
||||||
|
(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
|
(define-minor-mode vlf-mode
|
||||||
"Mode to browse large files in."
|
"Mode to browse large files in."
|
||||||
:lighter " VLF"
|
:lighter " VLF"
|
||||||
@ -507,7 +569,8 @@ bytes added to the end."
|
|||||||
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 (- 1 del-pos))))
|
||||||
((< start vlf-start-pos)
|
((< start vlf-start-pos)
|
||||||
(if (and (not vlf-partial-decode-shown)
|
(if (and (not vlf-partial-decode-shown)
|
||||||
(< (- vlf-start-pos start) 4))
|
(< (- vlf-start-pos start) 4))
|
||||||
@ -519,7 +582,8 @@ bytes added to the end."
|
|||||||
t nil edit-end-pos)))
|
t nil edit-end-pos)))
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(insert (delete-and-extract-region
|
(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))
|
(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))
|
||||||
@ -547,6 +611,7 @@ bytes added to the end."
|
|||||||
(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)
|
||||||
shifts))
|
shifts))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user