From bca579b2f3f1734664249ab9b380383c57f231d2 Mon Sep 17 00:00:00 2001 From: Justin Barclay Date: Sun, 14 Apr 2024 23:35:31 -0700 Subject: [PATCH] Fix bug where parinfer-rust-mode tried to load itself in wrong buffers 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 --- parinfer-rust-helper.el | 6 ++++-- parinfer-rust-mode.el | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/parinfer-rust-helper.el b/parinfer-rust-helper.el index e2f0e34..b9abc0d 100644 --- a/parinfer-rust-helper.el +++ b/parinfer-rust-helper.el @@ -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 diff --git a/parinfer-rust-mode.el b/parinfer-rust-mode.el index eacea6f..7e83089 100644 --- a/parinfer-rust-mode.el +++ b/parinfer-rust-mode.el @@ -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))))