diff options
-rw-r--r-- | lisp/km-magit.el | 45 |
1 files changed, 45 insertions, 0 deletions
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 |