Skip to content

Instantly share code, notes, and snippets.

@agzam
Last active June 30, 2020 23:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agzam/fbbf93aea842bf32e9403964e40b0dc0 to your computer and use it in GitHub Desktop.
Save agzam/fbbf93aea842bf32e9403964e40b0dc0 to your computer and use it in GitHub Desktop.
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