Skip to content

Commit

Permalink
Remember window position after formatting
Browse files Browse the repository at this point in the history
Suggested in issue #173.
  • Loading branch information
lassik committed Dec 10, 2022
1 parent 1f6b52a commit c156ffe
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions format-all.el
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit c156ffe

Please sign in to comment.