Skip to content

Instantly share code, notes, and snippets.

@agzam agzam/diff-buffers.el

Last active Jun 30, 2020
Embed
What would you like to do?
Diff two buffers
(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
You can’t perform that action at this time.