From 8d4911ed2db8a1ace388616bff35857559920f84 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sat, 21 Sep 2024 10:51:23 +0100 Subject: [PATCH 1/2] New user option 'diff-display-after-apply-hunk' * lisp/vc/diff-mode.el (diff-display-after-apply-hunk): New option. (diff-apply-hunk): Use it. * etc/NEWS: Announce the new option. --- etc/NEWS | 6 ++++++ lisp/vc/diff-mode.el | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/etc/NEWS b/etc/NEWS index 8bd5c7c9515..65e3a484e7a 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -304,6 +304,12 @@ according to diffs in the current buffer, but without applying the diffs to the original text. If the selected range extends a hunk, the command attempts to look up and copy the text in-between the hunks. +--- +*** New user option 'diff-display-after-apply-hunk'. +This option can be customized to nil to inhibit how, by default, +'diff-apply-hunk' displays the changed text after applying the hunk. +It can also be let-bound by Lisp code wrapping 'diff-apply-hunk'. + ** php-ts-mode --- diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index 4810b9ce01c..8af155c79e0 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el @@ -95,6 +95,10 @@ diff-advance-after-apply-hunk "Non-nil means `diff-apply-hunk' will move to the next hunk after applying." :type 'boolean) +(defcustom diff-display-after-apply-hunk t + "Non-nil means `diff-apply-hunk' will display the buffer it just changed." + :type 'boolean) + (defcustom diff-mode-hook nil "Run after setting up the `diff-mode' major mode." :type 'hook @@ -2024,7 +2028,8 @@ diff-apply-hunk (delete-region (car pos) (cdr pos)) (insert (car new))) ;; Display BUF in a window - (set-window-point (display-buffer buf) (+ (car pos) (cdr new))) + (when diff-display-after-apply-hunk + (set-window-point (display-buffer buf) (+ (car pos) (cdr new)))) (diff-hunk-status-msg line-offset (xor switched reverse) nil) (when diff-advance-after-apply-hunk (diff-hunk-next)))))) -- 2.39.5