1
0
mirror of https://github.com/m00natic/vlfi.git synced 2025-01-18 20:10:47 +00:00

Be more precise on restoring hexl-mode after chunk update has been

canceled.
This commit is contained in:
Andrey Kotlarski 2014-08-18 01:19:59 +03:00
parent 694d1de495
commit 557d751f78

View File

@ -136,92 +136,94 @@ bytes added to the end."
(length (encode-coding-region (length (encode-coding-region
(point-min) (point-max) (point-min) (point-max)
buffer-file-coding-system t)))) buffer-file-coding-system t))))
vlf-end-pos))) vlf-end-pos))
(cond (shifts
((or (< edit-end start) (< end vlf-start-pos) (cond
(not (verify-visited-file-modtime (current-buffer)))) ((or (< edit-end start) (< end vlf-start-pos)
(when (or (not modified) (not (verify-visited-file-modtime (current-buffer))))
(y-or-n-p "Chunk modified, are you sure? ")) ;full chunk renewal (when (or (not modified)
(set-buffer-modified-p nil) (y-or-n-p "Chunk modified, are you sure? ")) ;full chunk renewal
(let ((shifts (vlf-move-to-chunk-2 start end))) (set-buffer-modified-p nil)
(if restore-hexl (hexl-mode)) (vlf-move-to-chunk-2 start end)))
shifts))) ((and (= start vlf-start-pos) (= end edit-end))
((and (= start vlf-start-pos) (= end edit-end)) (or modified
(unless modified (vlf-move-to-chunk-2 start end)))
(let ((shifts (vlf-move-to-chunk-2 start end))) ((or (and (<= start vlf-start-pos) (<= edit-end end))
(if restore-hexl (hexl-mode)) (not modified)
shifts))) (y-or-n-p "Chunk modified, are you sure? "))
((or (and (<= start vlf-start-pos) (<= edit-end end)) (run-hooks 'vlf-before-chunk-update)
(not modified) (when (and hexl (not restore-hexl))
(y-or-n-p "Chunk modified, are you sure? ")) (if (consp buffer-undo-list)
(run-hooks 'vlf-before-chunk-update) (setq buffer-undo-list nil))
(when (and hexl (not restore-hexl)) (hexl-mode-exit))
(if (consp buffer-undo-list) (let ((shift-start 0)
(setq buffer-undo-list nil)) (shift-end 0))
(hexl-mode-exit)) (let ((pos (+ (position-bytes (point)) vlf-start-pos))
(let ((shift-start 0) (inhibit-read-only t))
(shift-end 0)) (cond ((= end vlf-start-pos)
(let ((pos (+ (position-bytes (point)) vlf-start-pos)) (or (eq buffer-undo-list t)
(inhibit-read-only t)) (setq buffer-undo-list nil))
(cond ((= end vlf-start-pos) (vlf-with-undo-disabled (erase-buffer))
(or (eq buffer-undo-list t) (setq modified nil))
(setq buffer-undo-list nil)) ((< end edit-end)
(vlf-with-undo-disabled (erase-buffer)) (setq end (car (vlf-delete-region
(setq modified nil)) (point-min) vlf-start-pos
((< end edit-end) edit-end end
(setq end (car (vlf-delete-region (min (or (byte-to-position
(point-min) vlf-start-pos edit-end (- end vlf-start-pos))
end (min (or (byte-to-position (point-min))
(- end vlf-start-pos)) (point-max))
(point-min)) nil))))
(point-max)) ((< edit-end end)
nil)))) (vlf-with-undo-disabled
((< edit-end end) (setq shift-end (cdr (vlf-insert-file-contents
(vlf-with-undo-disabled vlf-end-pos end nil t
(setq shift-end (cdr (vlf-insert-file-contents (point-max)))))))
vlf-end-pos end nil t (setq vlf-end-pos (+ end shift-end))
(point-max))))))) (cond ((= start edit-end)
(setq vlf-end-pos (+ end shift-end)) (or (eq buffer-undo-list t)
(cond ((= start edit-end) (setq buffer-undo-list nil))
(or (eq buffer-undo-list t) (vlf-with-undo-disabled
(setq buffer-undo-list nil)) (delete-region (point-min) (point)))
(vlf-with-undo-disabled (setq modified nil))
(delete-region (point-min) (point))) ((< vlf-start-pos start)
(setq modified nil)) (let ((del-info (vlf-delete-region
((< vlf-start-pos start) (point-min) vlf-start-pos
(let ((del-info (vlf-delete-region vlf-end-pos start
(point-min) vlf-start-pos (min (or
vlf-end-pos start (byte-to-position
(min (or (byte-to-position (- start vlf-start-pos))
(- start vlf-start-pos)) (point))
(point)) (point-max)) t)))
(point-max)) t))) (setq start (car del-info))
(setq start (car del-info)) (vlf-shift-undo-list (- (point-min)
(vlf-shift-undo-list (- (point-min) (cdr del-info)))))
(cdr del-info))))) ((< start vlf-start-pos)
((< start vlf-start-pos) (let ((edit-end-pos (point-max)))
(let ((edit-end-pos (point-max))) (vlf-with-undo-disabled
(vlf-with-undo-disabled (setq shift-start (car
(setq shift-start (car (vlf-insert-file-contents (vlf-insert-file-contents
start vlf-start-pos t nil start vlf-start-pos t nil
edit-end-pos))) 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) (vlf-shift-undo-list (- (point-max)
edit-end-pos))))) 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))
(point-max))) (point-max)))
(setq vlf-start-pos start)) (setq vlf-start-pos start))
(set-buffer-modified-p modified) (set-buffer-modified-p modified)
(set-visited-file-modtime) (set-visited-file-modtime)
(if hexl (hexl-mode)) (when hexl
(run-hooks 'vlf-after-chunk-update) (hexl-mode)
(cons shift-start shift-end))) (setq restore-hexl nil))
(restore-hexl (hexl-mode) (run-hooks 'vlf-after-chunk-update)
nil)))) (cons shift-start shift-end))))))
(if restore-hexl (hexl-mode))
shifts))
(defun vlf-move-to-chunk-2 (start end) (defun vlf-move-to-chunk-2 (start end)
"Unconditionally move to chunk enclosed by START END bytes. "Unconditionally move to chunk enclosed by START END bytes.