Last active
June 30, 2020 23:30
-
-
Save agzam/fbbf93aea842bf32e9403964e40b0dc0 to your computer and use it in GitHub Desktop.
Diff two buffers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun diff-buffers (buffer-A buffer-B) | |
"Diff two buffers." | |
(interactive | |
(let* ((only-two? (eq 2 (count-windows))) | |
(wins (sort (window-list) | |
(lambda (a b) (< (window-use-time a) | |
(window-use-time b))))) | |
(b1 (if only-two? | |
(window-buffer (first wins)) | |
(read-buffer "Buffer A to compare"))) | |
(b2 (if only-two? | |
(window-buffer (second wins)) | |
(read-buffer "Buffer B to compare")))) | |
(list b1 b2))) | |
(let ((old "/tmp/old-diff") | |
(new "/tmp/new-diff")) | |
(with-temp-file new | |
(insert-buffer-substring buffer-A)) | |
(with-temp-file old | |
(insert-buffer-substring buffer-B)) | |
(diff old new "-u" t))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment