Skip to content

Instantly share code, notes, and snippets.



Last active Jun 30, 2020
What would you like to do?
Diff two buffers
(defun diff-buffers (buffer-A buffer-B)
"Diff two buffers."
(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