mirror of
https://github.com/m00natic/vlfi.git
synced 2025-01-18 20:10:47 +00:00
Fix deletion when moving to partially overlapping chunk and enable more
intelligent behaviour in cases of overlapping and modifications.
This commit is contained in:
parent
f4ee23c07f
commit
a3901b8f1a
35
vlf.el
35
vlf.el
@ -341,11 +341,8 @@ If same as current chunk is requested, do nothing."
|
|||||||
(unless (and (= start vlf-start-pos)
|
(unless (and (= start vlf-start-pos)
|
||||||
(= end vlf-end-pos))
|
(= end vlf-end-pos))
|
||||||
(vlf-verify-size)
|
(vlf-verify-size)
|
||||||
(if (buffer-modified-p)
|
(if (vlf-move-to-chunk-1 start end)
|
||||||
(if (vlf-move-to-chunk-1 start end)
|
(or minimal (vlf-update-buffer-name)))))
|
||||||
(or minimal (vlf-update-buffer-name)))
|
|
||||||
(vlf-move-to-chunk-2 start end)
|
|
||||||
(or minimal (vlf-update-buffer-name)))))
|
|
||||||
|
|
||||||
(defun vlf-move-to-chunk-1 (start end)
|
(defun vlf-move-to-chunk-1 (start end)
|
||||||
"Move to chunk determined by START END keeping as much edits if any.
|
"Move to chunk determined by START END keeping as much edits if any.
|
||||||
@ -362,6 +359,7 @@ Return t if move hasn't been canceled."
|
|||||||
((or (<= edit-end start) (<= end vlf-start-pos))
|
((or (<= edit-end start) (<= end vlf-start-pos))
|
||||||
(when (or (not modified)
|
(when (or (not modified)
|
||||||
(y-or-n-p "Chunk modified, are you sure? ")) ;full chunk renewal
|
(y-or-n-p "Chunk modified, are you sure? ")) ;full chunk renewal
|
||||||
|
(set-buffer-modified-p nil)
|
||||||
(vlf-move-to-chunk-2 start end)
|
(vlf-move-to-chunk-2 start end)
|
||||||
t))
|
t))
|
||||||
((or (and (<= start vlf-start-pos) (<= edit-end end))
|
((or (and (<= start vlf-start-pos) (<= edit-end end))
|
||||||
@ -372,10 +370,15 @@ Return t if move hasn't been canceled."
|
|||||||
(shift-end 0)
|
(shift-end 0)
|
||||||
(inhibit-read-only t))
|
(inhibit-read-only t))
|
||||||
(cond ((< end edit-end)
|
(cond ((< end edit-end)
|
||||||
(vlf-with-undo-disabled
|
(let* ((del-pos (1+ (byte-to-position
|
||||||
(delete-region (byte-to-position
|
(- end vlf-start-pos))))
|
||||||
(1+ (- end vlf-start-pos)))
|
(del-len (length (encode-coding-region
|
||||||
(point-max))))
|
del-pos (point-max)
|
||||||
|
buffer-file-coding-system
|
||||||
|
t))))
|
||||||
|
(setq end (- vlf-end-pos del-len))
|
||||||
|
(vlf-with-undo-disabled
|
||||||
|
(delete-region del-pos (point-max)))))
|
||||||
((< edit-end end)
|
((< edit-end end)
|
||||||
(let ((edit-end-pos (point-max)))
|
(let ((edit-end-pos (point-max)))
|
||||||
(goto-char edit-end-pos)
|
(goto-char edit-end-pos)
|
||||||
@ -386,9 +389,15 @@ Return t if move hasn't been canceled."
|
|||||||
vlf-end-pos end nil t
|
vlf-end-pos end nil t
|
||||||
edit-end-pos)))))))
|
edit-end-pos)))))))
|
||||||
(cond ((< vlf-start-pos start)
|
(cond ((< vlf-start-pos start)
|
||||||
(vlf-with-undo-disabled
|
(let* ((del-pos (1+ (byte-to-position
|
||||||
(delete-region (point-min) (byte-to-position
|
(- start vlf-start-pos))))
|
||||||
(- start vlf-start-pos)))))
|
(del-len (length (encode-coding-region
|
||||||
|
(point-min) del-pos
|
||||||
|
buffer-file-coding-system
|
||||||
|
t))))
|
||||||
|
(setq start (+ vlf-start-pos del-len))
|
||||||
|
(vlf-with-undo-disabled
|
||||||
|
(delete-region (point-min) del-pos))))
|
||||||
((< 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)
|
||||||
@ -876,7 +885,7 @@ in file: %s" total-matches line regexp file)
|
|||||||
"Discard edit and refresh chunk from file."
|
"Discard edit and refresh chunk from file."
|
||||||
(interactive)
|
(interactive)
|
||||||
(set-buffer-modified-p nil)
|
(set-buffer-modified-p nil)
|
||||||
(vlf-move-to-chunk vlf-start-pos vlf-end-pos))
|
(vlf-move-to-chunk-2 vlf-start-pos vlf-end-pos))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;;; saving
|
;;; saving
|
||||||
|
Loading…
x
Reference in New Issue
Block a user