summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2022-10-14 23:49:01 -0700
committerSean Whitton <spwhitton@spwhitton.name>2022-10-18 12:40:47 -0700
commitf36a286d9ecba1b1c3e8856606e3a9570d03e78d (patch)
tree30e84cb8468553e239578cf2896d56929f10bee5
parentcd4563a9e62842e7a8f657fbf2577a731f8d49df (diff)
downloaddotfiles-f36a286d9ecba1b1c3e8856606e3a9570d03e78d.tar.gz
spw/diff-discard-hunk: save buffers that weren't already modified
-rw-r--r--.emacs.d/init.el14
1 files changed, 10 insertions, 4 deletions
diff --git a/.emacs.d/init.el b/.emacs.d/init.el
index fb31801b..ad2c90d5 100644
--- a/.emacs.d/init.el
+++ b/.emacs.d/init.el
@@ -3577,15 +3577,21 @@ mutt's review view, after exiting EDITOR."
(spw/feature-define-keys ((esh-mode eshell-mode-map))
"\C-z\C-c" spw/eshell-git-continue "\C-z\C-v" spw/eshell-git-abort)
-;; C-z C-v to discard changes, though without saving the modified buffer.
+;; C-z C-v to discard changes.
+;; Save only buffers that weren't already modified.
(defun spw/diff-discard-hunk ()
(interactive)
- (let ((beg (point))
- (diff-advance-after-apply-hunk t))
+ (let* ((beg (point))
+ (diff-advance-after-apply-hunk t)
+ (buffer (car (diff-find-source-location)))
+ (to-save (and (not (buffer-modified-p buffer)) buffer)))
(diff-apply-hunk t)
(unless (= beg (point))
(diff-hunk-next -1)
- (diff-hunk-kill))))
+ (diff-hunk-kill))
+ (when to-save
+ (with-current-buffer to-save
+ (basic-save-buffer)))))
(spw/feature-define-keys diff-mode "\C-z\C-v" spw/diff-discard-hunk)
(defun spw/vc-next-action-for-git-fixup ()