From c156ffe5f3c979ab89fd941658e840801078d091 Mon Sep 17 00:00:00 2001 From: Lassi Kortela Date: Sat, 10 Dec 2022 18:08:43 +0200 Subject: [PATCH] Remember window position after formatting Suggested in issue #173. --- format-all.el | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/format-all.el b/format-all.el index 13fba981..fe0ae4a0 100644 --- a/format-all.el +++ b/format-all.el @@ -1484,12 +1484,15 @@ STATUS and ERROR-OUTPUT come from the formatter." (defun format-all--save-line-number (thunk) "Internal helper function to run THUNK and go back to the same line." (let ((old-line-number (line-number-at-pos)) - (old-column (current-column))) + (old-column (current-column)) + (old-window (selected-window)) + (old-window-start (window-start))) (funcall thunk) (goto-char (point-min)) (forward-line (1- old-line-number)) (let ((line-length (- (point-at-eol) (point-at-bol)))) - (goto-char (+ (point) (min old-column line-length)))))) + (goto-char (+ (point) (min old-column line-length)))) + (set-window-start old-window old-window-start))) (defun format-all--run-chain (language chain region) "Internal function to run a formatter CHAIN on the current buffer.