Skip to content

Commit 764912a

Browse files
newt0311dakra
authored andcommitted
Save position in all windows with buffer
Originally, this logic only saved the position in the current window for the buffer. If the same buffer is open in multiple windows, all the other windows would jump to the beginning of the buffer. This can be rather distracting when working on a complex module. With this change, the buffer position is saved and restored for all windows with the affected buffer. Fix #49
1 parent 563c744 commit 764912a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

blacken.el

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@ Return black process the exit code."
144144
Show black output, if black exit abnormally and DISPLAY is t."
145145
(interactive (list t))
146146
(let* ((original-buffer (current-buffer))
147-
(original-point (point))
148-
(original-window-pos (window-start))
147+
(original-window-states (mapcar
148+
(lambda (w)
149+
(list w (window-point w) (window-start w)))
150+
(get-buffer-window-list)))
149151
(tmpbuf (get-buffer-create "*blacken*"))
150152
(errbuf (get-buffer-create "*blacken-error*")))
151153
;; This buffer can be left after previous black invocation. It
@@ -159,8 +161,9 @@ Show black output, if black exit abnormally and DISPLAY is t."
159161
(unless (eq (compare-buffer-substrings tmpbuf nil nil original-buffer nil nil) 0)
160162
(with-current-buffer tmpbuf
161163
(copy-to-buffer original-buffer (point-min) (point-max)))
162-
(goto-char original-point)
163-
(set-window-start (selected-window) original-window-pos))
164+
(dolist (win-stt original-window-states)
165+
(set-window-point (car win-stt) (nth 1 win-stt))
166+
(set-window-start (car win-stt) (nth 2 win-stt))))
164167
(mapc 'kill-buffer (list tmpbuf errbuf)))
165168
(error (message "%s" (error-message-string err))
166169
(when display

0 commit comments

Comments
 (0)