mirror of
https://github.com/m00natic/vlfi.git
synced 2025-01-31 02:00:47 +00:00
Use single ediff pass to adjust borders. Protect against user
interruption while searching for difference.
This commit is contained in:
parent
d5d9cd71ee
commit
5d30eb4826
52
vlf-ediff.el
52
vlf-ediff.el
@ -157,6 +157,7 @@ logical chunks in case there is no difference at the current ones."
|
|||||||
(set-buffer buffer-A)
|
(set-buffer buffer-A)
|
||||||
(setq buffer-A (current-buffer)) ;names change, so reference by buffer object
|
(setq buffer-A (current-buffer)) ;names change, so reference by buffer object
|
||||||
(let ((end-A (= vlf-start-pos vlf-end-pos))
|
(let ((end-A (= vlf-start-pos vlf-end-pos))
|
||||||
|
(chunk-A (cons vlf-start-pos vlf-end-pos))
|
||||||
(point-max-A (point-max))
|
(point-max-A (point-max))
|
||||||
(min-file-size vlf-file-size)
|
(min-file-size vlf-file-size)
|
||||||
(forward-p (eq next-func 'vlf-next-chunk)))
|
(forward-p (eq next-func 'vlf-next-chunk)))
|
||||||
@ -164,21 +165,24 @@ logical chunks in case there is no difference at the current ones."
|
|||||||
(setq buffer-B (current-buffer)
|
(setq buffer-B (current-buffer)
|
||||||
min-file-size (min min-file-size vlf-file-size))
|
min-file-size (min min-file-size vlf-file-size))
|
||||||
(let ((end-B (= vlf-start-pos vlf-end-pos))
|
(let ((end-B (= vlf-start-pos vlf-end-pos))
|
||||||
|
(chunk-B (cons vlf-start-pos vlf-end-pos))
|
||||||
|
(done nil)
|
||||||
(reporter (make-progress-reporter
|
(reporter (make-progress-reporter
|
||||||
"Searching for difference..."
|
"Searching for difference..."
|
||||||
(if forward-p vlf-start-pos
|
(if forward-p vlf-start-pos
|
||||||
(- min-file-size vlf-end-pos))
|
(- min-file-size vlf-end-pos))
|
||||||
min-file-size)))
|
min-file-size)))
|
||||||
|
(unwind-protect
|
||||||
|
(progn
|
||||||
(while (and (or (not end-A) (not end-B))
|
(while (and (or (not end-A) (not end-B))
|
||||||
(or (zerop (compare-buffer-substrings
|
(or (zerop (compare-buffer-substrings
|
||||||
buffer-A (point-min) point-max-A
|
buffer-A (point-min) point-max-A
|
||||||
buffer-B (point-min) (point-max)))
|
buffer-B (point-min) (point-max)))
|
||||||
(with-current-buffer ediff-buffer
|
(with-current-buffer ediff-buffer
|
||||||
(ediff-update-diffs)
|
(ediff-update-diffs)
|
||||||
(when (and (not end-A) (not end-B))
|
(and (not end-A) (not end-B)
|
||||||
(vlf-ediff-adjust buffer-A buffer-B)
|
(vlf-ediff-refine buffer-A
|
||||||
(or (zerop ediff-number-of-differences)
|
buffer-B))
|
||||||
(vlf-ediff-adjust buffer-A buffer-B t)))
|
|
||||||
(zerop ediff-number-of-differences))))
|
(zerop ediff-number-of-differences))))
|
||||||
(funcall next-func)
|
(funcall next-func)
|
||||||
(setq end-B (= vlf-start-pos vlf-end-pos))
|
(setq end-B (= vlf-start-pos vlf-end-pos))
|
||||||
@ -188,7 +192,8 @@ logical chunks in case there is no difference at the current ones."
|
|||||||
point-max-A (point-max)))
|
point-max-A (point-max)))
|
||||||
(progress-reporter-update reporter
|
(progress-reporter-update reporter
|
||||||
(if forward-p vlf-end-pos
|
(if forward-p vlf-end-pos
|
||||||
(- vlf-file-size vlf-start-pos))))
|
(- vlf-file-size
|
||||||
|
vlf-start-pos))))
|
||||||
(progress-reporter-done reporter)
|
(progress-reporter-done reporter)
|
||||||
(if (or (not end-A) (not end-B))
|
(if (or (not end-A) (not end-B))
|
||||||
(progn (vlf-update-buffer-name)
|
(progn (vlf-update-buffer-name)
|
||||||
@ -199,20 +204,40 @@ logical chunks in case there is no difference at the current ones."
|
|||||||
(vlf-move-to-chunk (- max-file-size vlf-batch-size)
|
(vlf-move-to-chunk (- max-file-size vlf-batch-size)
|
||||||
max-file-size)
|
max-file-size)
|
||||||
(set-buffer buffer-A)
|
(set-buffer buffer-A)
|
||||||
(setq max-file-size (max max-file-size vlf-file-size))
|
(setq max-file-size (max max-file-size
|
||||||
(vlf-move-to-chunk (- max-file-size vlf-batch-size)
|
vlf-file-size))
|
||||||
|
(vlf-move-to-chunk (- max-file-size
|
||||||
|
vlf-batch-size)
|
||||||
max-file-size))
|
max-file-size))
|
||||||
(vlf-beginning-of-file)
|
(vlf-beginning-of-file)
|
||||||
(set-buffer buffer-A)
|
(set-buffer buffer-A)
|
||||||
(vlf-beginning-of-file))
|
(vlf-beginning-of-file))
|
||||||
(set-buffer ediff-buffer)
|
(set-buffer ediff-buffer)
|
||||||
(ediff-update-diffs)
|
(ediff-update-diffs)
|
||||||
(when (or (not forward-p)
|
(if (or (not forward-p)
|
||||||
(and (not end-A) (not end-B)))
|
(and (not end-A) (not end-B)))
|
||||||
|
(vlf-ediff-refine buffer-A buffer-B)))
|
||||||
|
(setq done t))
|
||||||
|
(unless done
|
||||||
|
(set-buffer buffer-A)
|
||||||
|
(set-buffer-modified-p nil)
|
||||||
|
(vlf-move-to-chunk (car chunk-A) (cdr chunk-A) t)
|
||||||
|
(set-buffer buffer-B)
|
||||||
|
(set-buffer-modified-p nil)
|
||||||
|
(vlf-move-to-chunk (car chunk-B) (cdr chunk-B) t)
|
||||||
|
(set-buffer ediff-buffer)
|
||||||
|
(ediff-update-diffs)
|
||||||
|
(vlf-ediff-refine buffer-A buffer-B))))))
|
||||||
|
|
||||||
|
(defun vlf-ediff-refine (buffer-A buffer-B)
|
||||||
|
"Try to minimize differences between BUFFER-A and BUFFER-B.
|
||||||
|
This can happen if first or last difference is at the start/end of
|
||||||
|
buffer."
|
||||||
(or (zerop ediff-number-of-differences)
|
(or (zerop ediff-number-of-differences)
|
||||||
(vlf-ediff-adjust buffer-A buffer-B))
|
(let ((adjust-p (vlf-ediff-adjust buffer-A buffer-B)))
|
||||||
(or (zerop ediff-number-of-differences)
|
(setq adjust-p (or (vlf-ediff-adjust buffer-A buffer-B t)
|
||||||
(vlf-ediff-adjust buffer-A buffer-B t)))))))
|
adjust-p))
|
||||||
|
(if adjust-p (ediff-update-diffs)))))
|
||||||
|
|
||||||
(defun vlf-ediff-adjust (buf-A buf-B &optional end)
|
(defun vlf-ediff-adjust (buf-A buf-B &optional end)
|
||||||
"Additionally adjust buffer borders for BUF-A and BUF-B.
|
"Additionally adjust buffer borders for BUF-A and BUF-B.
|
||||||
@ -221,8 +246,7 @@ Adjust beginning if END is nil."
|
|||||||
(diff-A (ediff-get-diff-overlay diff-num 'A))
|
(diff-A (ediff-get-diff-overlay diff-num 'A))
|
||||||
(diff-B (ediff-get-diff-overlay diff-num 'B))
|
(diff-B (ediff-get-diff-overlay diff-num 'B))
|
||||||
diff-A-str diff-B-str adjust-p)
|
diff-A-str diff-B-str adjust-p)
|
||||||
(save-excursion
|
(with-current-buffer buf-A
|
||||||
(set-buffer buf-A)
|
|
||||||
(setq adjust-p (if end (= (overlay-end diff-A) (point-max))
|
(setq adjust-p (if end (= (overlay-end diff-A) (point-max))
|
||||||
(= (overlay-start diff-A) (point-min)))
|
(= (overlay-start diff-A) (point-min)))
|
||||||
diff-A-str (and adjust-p (buffer-substring-no-properties
|
diff-A-str (and adjust-p (buffer-substring-no-properties
|
||||||
@ -248,7 +272,7 @@ Adjust beginning if END is nil."
|
|||||||
(or (funcall adjust-func diff-B-str diff-A-str buf-A)
|
(or (funcall adjust-func diff-B-str diff-A-str buf-A)
|
||||||
(setq adjust-p nil)))
|
(setq adjust-p nil)))
|
||||||
(t (setq adjust-p nil))))))
|
(t (setq adjust-p nil))))))
|
||||||
(if adjust-p (ediff-update-diffs))))
|
adjust-p))
|
||||||
|
|
||||||
(defun vlf-ediff-adjust-start (diff-short diff-long vlf-buffer)
|
(defun vlf-ediff-adjust-start (diff-short diff-long vlf-buffer)
|
||||||
"Remove difference between DIFF-SHORT and DIFF-LONG from beginning\
|
"Remove difference between DIFF-SHORT and DIFF-LONG from beginning\
|
||||||
|
Loading…
x
Reference in New Issue
Block a user