From c289c114ac381105cb550b3805041ad5cf5e61a5 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Sun, 18 Aug 2024 17:26:01 +0200 Subject: [PATCH 2/2] Add new macro to restore the scroll position of a window * lisp/subr.el (save-window-start): Add macro. --- lisp/subr.el | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lisp/subr.el b/lisp/subr.el index 9ea18ca5bff..003e27f2ad7 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -4922,6 +4922,16 @@ save-window-excursion (unwind-protect (progn ,@body) (set-window-configuration ,c))))) +(defmacro save-window-start (&rest body) + "Execute BODY, then restore the starting position of the selected window." + (declare (indent 0) (debug t)) + (let ((window (make-symbol "window")) + (start (make-symbol "start"))) + `(let* ((,window (selected-window)) + (,start (window-start ,window))) + (unwind-protect ,(macroexp-progn body) + (set-window-start ,window ,start t))))) + (defun internal-temp-output-buffer-show (buffer) "Internal function for `with-output-to-temp-buffer'." (with-current-buffer buffer -- 2.46.0