1
0
mirror of https://github.com/m00natic/vlfi.git synced 2025-02-07 05:30:47 +00:00

Fix vlf-shift-undo-list to reverse resulting list.

This commit is contained in:
Andrey Kotlarski 2013-12-21 00:18:36 +02:00
parent c58d0d84ff
commit 2470fc0f67

123
vlf.el
View File

@ -116,63 +116,64 @@ continuously recenter.")
(defun vlf-shift-undo-list (n) (defun vlf-shift-undo-list (n)
"Shift undo list element regions by N." "Shift undo list element regions by N."
(or (eq buffer-undo-list t) (or (eq buffer-undo-list t)
(let (undo-list) (setq buffer-undo-list
(setq buffer-undo-list (nreverse
(catch 'end (let ((min (point-min))
(dolist (el buffer-undo-list) undo-list)
(push (catch 'end
(cond (dolist (el buffer-undo-list undo-list)
((null el) nil) (push
((numberp el) (let ((pos (+ el n))) (cond
(if (< n 0) ((null el) nil)
(throw 'end undo-list) ((numberp el) (let ((pos (+ el n)))
pos))) (if (< pos min)
(t (let ((head (car el))) (throw 'end undo-list)
(cond ((numberp head) pos)))
(let ((beg (+ head n))) (t (let ((head (car el)))
(if (< beg 0) (cond ((numberp head)
(throw 'end undo-list) (let ((beg (+ head n)))
(cons beg (+ (cdr el) n))))) (if (< beg min)
((stringp head) (throw 'end undo-list)
(let* ((pos (cdr el)) (cons beg (+ (cdr el) n)))))
(positive (< 0 pos)) ((stringp head)
(new (+ (abs pos) n))) (let* ((pos (cdr el))
(if (< new 0) (positive (< 0 pos))
(throw 'end undo-list) (new (+ (abs pos) n)))
(cons head (if positive (if (< new min)
new (throw 'end undo-list)
(- new)))))) (cons head (if positive
((null head) new
(let ((beg (+ (nth 3 el) n))) (- new))))))
(if (< beg 0) ((null head)
(throw 'end undo-list) (let ((beg (+ (nth 3 el) n)))
(cons (if (< beg min)
nil (throw 'end undo-list)
(cons (cons
(cadr el) nil
(cons (cons
(nth 2 el) (cadr 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 (cons
(+ (nth 3 el) n) (nth 2 el)
(cons (nth 4 el) (cons beg
(cdr (last el)))))))))) (+ (cddr
(t el))))) (cddr el)) n))))))))
undo-list)) ((and (eq head 'apply)
undo-list))))) (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."
@ -551,9 +552,10 @@ Return t if move hasn't been canceled."
buffer-file-coding-system buffer-file-coding-system
t)))) t))))
(setq start (+ vlf-start-pos del-len)) (setq start (+ vlf-start-pos del-len))
(vlf-with-undo-disabled (let ((del-length (- (point-min) del-pos)))
(delete-region (point-min) del-pos)) (vlf-with-undo-disabled
(vlf-shift-undo-list (- del-len)))) (delete-region (point-min) del-pos))
(vlf-shift-undo-list del-length))))
((< 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)
@ -588,8 +590,7 @@ Return t if move hasn't been canceled."
(erase-buffer) (erase-buffer)
(insert-file-contents buffer-file-name nil (insert-file-contents buffer-file-name nil
vlf-start-pos vlf-end-pos) vlf-start-pos vlf-end-pos)
(let ((shifts (vlf-adjust-chunk vlf-start-pos vlf-end-pos t (let ((shifts (vlf-adjust-chunk vlf-start-pos vlf-end-pos t t)))
t)))
(setq vlf-start-pos (- vlf-start-pos (car shifts)) (setq vlf-start-pos (- vlf-start-pos (car shifts))
vlf-end-pos (+ vlf-end-pos (cdr shifts))) vlf-end-pos (+ vlf-end-pos (cdr shifts)))
(goto-char (or (byte-to-position (+ pos (car shifts))) (goto-char (or (byte-to-position (+ pos (car shifts)))
@ -598,8 +599,8 @@ Return t if move hasn't been canceled."
(setq buffer-undo-list 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 adjust-start adjust-end
position) &optional position)
"Adjust chunk at absolute START to END till content can be\ "Adjust chunk at absolute START to END till content can be\
properly decoded. ADJUST-START determines if trying to prepend bytes\ properly decoded. ADJUST-START determines if trying to prepend bytes\
to the beginning, ADJUST-END - append to the end. to the beginning, ADJUST-END - append to the end.