Skip to content

Commit

Permalink
Don't try to reset state if last window is undefined
Browse files Browse the repository at this point in the history
`old-selected-window` may return a frame instead of a window, or `nil` if there
is not a previous window selection (e.g. at Emacs startup). In either of these
cases, trying to find the old buffer and reset its state would produce an error,
so do nothing instead.
  • Loading branch information
ttuegel committed Nov 5, 2023
1 parent ffeb514 commit 5b7ab9c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions boon-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,10 @@ the buffer changes."
;; surprising to the user when coming back to it).
(defun boon-reset-state-for-switchw (new-frame)
"Reset the boon state to natural when switching windows."
(let* ((old (old-selected-window))
(prev-buf (window-buffer old)))
(with-current-buffer prev-buf
(-when-let* ((old-frame-or-window (old-selected-window)) ; `old-selected-window' sometimes (surprisingly) returns a frame.
(old-window (and (windowp old-frame-or-window) old-frame-or-window))
(old-buffer (window-buffer old-window)))
(with-current-buffer old-buffer
(boon-set-natural-state))))

(add-hook 'window-selection-change-functions #'boon-reset-state-for-switchw)
Expand Down

0 comments on commit 5b7ab9c

Please sign in to comment.