1
0
mirror of https://github.com/m00natic/vlfi.git synced 2025-02-12 07:58:09 +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

29
vlf.el
View File

@ -116,35 +116,37 @@ 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
(let ((min (point-min))
undo-list)
(catch 'end (catch 'end
(dolist (el buffer-undo-list) (dolist (el buffer-undo-list undo-list)
(push (push
(cond (cond
((null el) nil) ((null el) nil)
((numberp el) (let ((pos (+ el n))) ((numberp el) (let ((pos (+ el n)))
(if (< n 0) (if (< pos min)
(throw 'end undo-list) (throw 'end undo-list)
pos))) pos)))
(t (let ((head (car el))) (t (let ((head (car el)))
(cond ((numberp head) (cond ((numberp head)
(let ((beg (+ head n))) (let ((beg (+ head n)))
(if (< beg 0) (if (< beg min)
(throw 'end undo-list) (throw 'end undo-list)
(cons beg (+ (cdr el) n))))) (cons beg (+ (cdr el) n)))))
((stringp head) ((stringp head)
(let* ((pos (cdr el)) (let* ((pos (cdr el))
(positive (< 0 pos)) (positive (< 0 pos))
(new (+ (abs pos) n))) (new (+ (abs pos) n)))
(if (< new 0) (if (< new min)
(throw 'end undo-list) (throw 'end undo-list)
(cons head (if positive (cons head (if positive
new new
(- new)))))) (- new))))))
((null head) ((null head)
(let ((beg (+ (nth 3 el) n))) (let ((beg (+ (nth 3 el) n)))
(if (< beg 0) (if (< beg min)
(throw 'end undo-list) (throw 'end undo-list)
(cons (cons
nil nil
@ -158,7 +160,7 @@ continuously recenter.")
((and (eq head 'apply) ((and (eq head 'apply)
(numberp (cadr el))) (numberp (cadr el)))
(let ((beg (+ (nth 2 el) n))) (let ((beg (+ (nth 2 el) n)))
(if (< beg 0) (if (< beg min)
(throw 'end undo-list) (throw 'end undo-list)
(cons (cons
'apply 'apply
@ -171,8 +173,7 @@ continuously recenter.")
(cons (nth 4 el) (cons (nth 4 el)
(cdr (last el)))))))))) (cdr (last el))))))))))
(t el))))) (t el)))))
undo-list)) 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."
@ -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))
(let ((del-length (- (point-min) del-pos)))
(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)))) (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.