Skip to content

Instantly share code, notes, and snippets.

@unhammer
Created June 4, 2024 13:37
Show Gist options
  • Save unhammer/f53f56a656da9489e5caffa389b18afb to your computer and use it in GitHub Desktop.
Save unhammer/f53f56a656da9489e5caffa389b18afb to your computer and use it in GitHub Desktop.
Hit C-x =, mark a region, C-M-c to confirm, mark a second region, C-M-c to confirm and you have an ediff of regions of the same buffer
(defun ediff--regions-samebuffer (ediff-regions &optional startup-hooks)
(let ((cloned-buffer (clone-indirect-buffer-other-window nil t)))
(unwind-protect
(funcall ediff-regions (current-buffer) cloned-buffer startup-hooks)
(kill-buffer cloned-buffer))))
(defun ediff-regions-samebuffer (&optional wordwise startup-hooks)
"Ediff two regions of the same buffer, automating the clone-and-narrow dance.
Optional interactive argument WORDWISE to do a word-diff instead of line-by-line."
(interactive "P")
(if wordwise
(ediff--regions-samebuffer #'ediff-regions-wordwise startup-hooks)
(ediff--regions-samebuffer #'ediff-regions-linewise startup-hooks)))
(global-set-key (kbd "C-x =") #'ediff-regions-samebuffer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment