Created
October 12, 2011 00:21
-
-
Save zdavkeos/1279865 to your computer and use it in GitHub Desktop.
Emacs diff-region
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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; diff-region* - Diff two regions | |
;; | |
;; To compare two regions, select the first region | |
;; and run `diff-region`. The region is now copied | |
;; to a seperate diff-ing buffer. Next, navigate | |
;; to the next region in question (even in another file). | |
;; Mark the region and run `diff-region-now`, the diff | |
;; of the two regions will be displayed by ediff. | |
;; | |
;; You can re-select the first region at any time | |
;; by re-calling `diff-region`. | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
(defun diff-region () | |
"Select a region to compare" | |
(interactive) | |
(when (use-region-p) ; there is a region | |
(let (buf) | |
(setq buf (get-buffer-create "*Diff-regionA*")) | |
(save-current-buffer | |
(set-buffer buf) | |
(erase-buffer)) | |
(append-to-buffer buf (region-beginning) (region-end))) | |
) | |
(message "Now select other region to compare and run `diff-region-now`") | |
) | |
(defun diff-region-now () | |
"Compare current region with region already selected by `diff-region`" | |
(interactive) | |
(when (use-region-p) | |
(let (bufa bufb) | |
(setq bufa (get-buffer-create "*Diff-regionA*")) | |
(setq bufb (get-buffer-create "*Diff-regionB*")) | |
(save-current-buffer | |
(set-buffer bufb) | |
(erase-buffer)) | |
(append-to-buffer bufb (region-beginning) (region-end)) | |
(ediff-buffers bufa bufb)) | |
) | |
) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@rashack: Sure you can. Just select the same buffer in both prompts.