summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2021-01-10 19:47:15 -0500
committerKyle Meyer <kyle@kyleam.com>2021-06-12 01:10:42 -0400
commit21da2e32cc9e4df8564e5eaafa8498a4e3b1b2bf (patch)
treefefeaa67350b484e32f0c9d022baeb02874d3890 /lisp
parent73a3f15b469af96b9c6ec6e49b101212a97b766c (diff)
downloademacs.d-21da2e32cc9e4df8564e5eaafa8498a4e3b1b2bf.tar.gz
magit: Add commands to dump diff or patch to a buffer
Diffstat (limited to 'lisp')
-rw-r--r--lisp/km-magit.el45
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