Skip to content

Instantly share code, notes, and snippets.

@nikomatsakis
Created April 23, 2013 14:01
Show Gist options
  • Save nikomatsakis/5443789 to your computer and use it in GitHub Desktop.
Save nikomatsakis/5443789 to your computer and use it in GitHub Desktop.
elisp to move diff hunks to another buffer
(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