Skip to content

Commit

Permalink
Fix bug where parinfer-rust-mode tried to load itself in wrong buffers
Browse files Browse the repository at this point in the history
window-selection-change-functions run when a window change
happens. This means it happens when you enter into a window and when
you leave. This should have been obvious but it wasn't and I wasted a
day hunting this down
  • Loading branch information
justinbarclay committed Apr 15, 2024
1 parent 946bf56 commit bca579b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions parinfer-rust-helper.el
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,10 @@ mode to better emulate users."
(t num))))
(defun parinfer-rust--defer-loading (&rest _)
"Defer loading of `parinfer-rust-mode' until the buffer is in focus."
(when (eq (current-buffer)
(window-buffer (selected-window)))
;; This is a parinfer enabled buffer that started in the background and has now been moved to the foreground
(when (and parinfer-rust-enabled
(eq (current-buffer)
(window-buffer (selected-window))))
(remove-hook 'window-selection-change-functions #'parinfer-rust--defer-loading t)
(parinfer-rust-mode-enable)))
;; Disable fill column warning only for this buffer to enable long strings of text without
Expand Down
4 changes: 4 additions & 0 deletions parinfer-rust-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,12 @@ not available."
(parinfer-rust-enabled
(parinfer-rust-mode-disable))
;; Don't do anything if the buffer is not selected
;; TODO: Come up with a better way to defer and disable loading
;; Defer waits for window selection change and disabled waits for a change event
;; there is also the idea of deferring the running of parinfer vs deferring the loading
((not (eq (current-buffer)
(window-buffer (selected-window))))
(setq-local parinfer-rust-enabled t)
(add-hook 'window-selection-change-functions #'parinfer-rust--defer-loading nil t))
(t
(parinfer-rust-mode-enable))))
Expand Down

0 comments on commit bca579b

Please sign in to comment.