From 21da2e32cc9e4df8564e5eaafa8498a4e3b1b2bf Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Sun, 10 Jan 2021 19:47:15 -0500 Subject: magit: Add commands to dump diff or patch to a buffer --- lisp/km-magit.el | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'lisp') diff --git a/lisp/km-magit.el b/lisp/km-magit.el index 39e3b64..f6f4cdf 100644 --- a/lisp/km-magit.el +++ b/lisp/km-magit.el @@ -930,6 +930,51 @@ appending [M/N] to each entry." (auto-fill-mode 1) (flyspell-mode 1)))) +;;;###autoload +(defun km/magit-dump-diff-to-buffer (&optional arg) + "Like `magit-patch-save', but dump output to a buffer." + ;; Note: Nearly all of this is just copied from `magit-patch-save'. + (interactive "P") + (require 'magit-patch) + (unless (derived-mode-p 'magit-diff-mode) + (user-error "Only diff buffers can be saved as patches")) + (let ((rev magit-buffer-range) + (typearg magit-buffer-typearg) + (args magit-buffer-diff-args) + (files magit-buffer-diff-files)) + (cond ((eq magit-patch-save-arguments 'buffer) + (when arg + (setq args nil))) + ((eq (car-safe magit-patch-save-arguments) 'exclude) + (unless arg + (setq args (-difference args (cdr magit-patch-save-arguments))))) + ((not arg) + (setq args magit-patch-save-arguments))) + (with-current-buffer + (generate-new-buffer + (replace-regexp-in-string + "^\\*" "*diff dump: " + (funcall magit-generate-buffer-name-function + major-mode (magit-buffer-value)))) + (magit-git-insert "diff" rev "-p" typearg args "--" files) + (pop-to-buffer (current-buffer))))) + +;;;###autoload +(defun km/magit-dump-patch-to-buffer () + (interactive) + (require 'magit-patch) + (unless (derived-mode-p 'magit-revision-mode) + (user-error "Not revision buffer")) + (let ((rev magit-buffer-revision)) + (with-current-buffer + (generate-new-buffer + (replace-regexp-in-string + "^\\*" "*patch dump: " + (funcall magit-generate-buffer-name-function + major-mode (magit-buffer-value)))) + (magit-git-insert "format-patch" "--stdout" (concat rev "^-1")) + (pop-to-buffer (current-buffer))))) + ;;; Copy functions -- cgit v1.2.3