Created
April 23, 2013 14:01
-
-
Save nikomatsakis/5443789 to your computer and use it in GitHub Desktop.
elisp to move diff hunks to another buffer
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
(defun diff-hunk-move (dest-buffer) | |
"Move current hunk to another buffer." | |
(interactive "bBuffer to move to:") | |
(save-excursion | |
(let* ((start | |
(point)) | |
(start-of-file | |
(ignore-errors | |
(goto-char start) | |
(diff-beginning-of-file) | |
(point))) | |
(first-hunk | |
(ignore-errors | |
(goto-char start) | |
(diff-beginning-of-file) | |
(diff-hunk-next) | |
(point)))) | |
(kill-ring-save start-of-file first-hunk) ; Copy file header | |
(diff-hunk-yank-in-buffer dest-buffer) | |
(goto-char start) ; Copy the hunk itself | |
(diff-end-of-hunk) | |
(kill-ring-save start (point)) | |
(diff-hunk-yank-in-buffer dest-buffer)))) | |
(defun diff-hunk-yank-in-buffer (dest-buffer) | |
(let* (old-buffer (current-buffer)) | |
(switch-to-buffer dest-buffer) | |
(end-of-buffer) | |
(yank) | |
(switch-to-buffer old-buffer))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment