Skip to content

Commit

Permalink
Defer running parinfer-rust-mode for the first time until it is the
Browse files Browse the repository at this point in the history
active buffer
  • Loading branch information
justinbarclay committed Apr 2, 2024
1 parent ec2f9ae commit 1feef70
Showing 1 changed file with 40 additions and 28 deletions.
68 changes: 40 additions & 28 deletions parinfer-rust-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,13 @@ parinfer autofix them, or if there is no reasonable way for
(parinfer-rust-mode -1))
(remove-hook 'before-change-functions #'parinfer-rust--check-for-issues t))

(defun parinfer-rust-mode-defer-loading (&rest _)
"Defer loading of `parinfer-rust-mode' until the buffer is in focus."
(when (eq (current-buffer)
(window-buffer (selected-window)))
(remove-hook 'window-selection-change-functions #'parinfer-rust-mode-defer-loading t)
(parinfer-rust-mode)))

(defun parinfer-rust--switch-mode (&optional mode)
"Switch to a different Parinfer MODE.
Expand Down Expand Up @@ -569,35 +576,40 @@ not available."
:lighter (:eval (concat " parinfer:" parinfer-rust--mode))
:init-value nil
:keymap parinfer-rust-mode-map
(if parinfer-rust-enabled
(parinfer-rust-mode-disable)
(cond
(parinfer-rust-enabled
(parinfer-rust-mode-disable))
((not (eq (current-buffer)
(window-buffer (selected-window))))
(add-hook 'window-selection-change-functions #'parinfer-rust-mode-defer-loading nil t))
(t
(progn
;; Make sure the library is installed at the appropriate location or offer to download it
(when (parinfer-rust--check-for-library parinfer-rust-supported-versions
parinfer-rust-library
parinfer-rust--lib-name
parinfer-rust-auto-download)
(require 'parinfer-rust parinfer-rust-library t))
;; Check version and prompt to download latest version if out of date Problem: Emacs can't
;; reload dynamic libraries, which means that if we download a new library the user has to
;; restart Emacs for changes to take effect.
(parinfer-rust--check-version parinfer-rust-supported-versions
(parinfer-rust-version)
parinfer-rust-library
parinfer-rust--lib-name)
(parinfer-rust-mode-enable)
(cond ((or (eq 'defer parinfer-rust-check-before-enable)
buffer-read-only)
;; Defer checking for changes until a user changes the buffer
(setq-local parinfer-rust--disable t)
(add-hook 'before-change-functions #'parinfer-rust--check-for-issues t t))

((eq 'immediate parinfer-rust-check-before-enable)
(setq-local parinfer-rust--disable t)
(parinfer-rust--check-for-issues))

(t (let ((parinfer-rust--mode "paren"))
(parinfer-rust--execute)))))))
;; Make sure the library is installed at the appropriate location or offer to download it
(when (parinfer-rust--check-for-library parinfer-rust-supported-versions
parinfer-rust-library
parinfer-rust--lib-name
parinfer-rust-auto-download)
(require 'parinfer-rust parinfer-rust-library t))
;; Check version and prompt to download latest version if out of date Problem: Emacs can't
;; reload dynamic libraries, which means that if we download a new library the user has to
;; restart Emacs for changes to take effect.
(parinfer-rust--check-version parinfer-rust-supported-versions
(parinfer-rust-version)
parinfer-rust-library
parinfer-rust--lib-name)
(parinfer-rust-mode-enable)
(cond ((or (eq 'defer parinfer-rust-check-before-enable)
buffer-read-only)
;; Defer checking for changes until a user changes the buffer
(setq-local parinfer-rust--disable t)
(add-hook 'before-change-functions #'parinfer-rust--check-for-issues t t))

((eq 'immediate parinfer-rust-check-before-enable)
(setq-local parinfer-rust--disable t)
(parinfer-rust--check-for-issues))

(t (let ((parinfer-rust--mode "paren"))
(parinfer-rust--execute))))))))

(provide 'parinfer-rust-mode)
;;; parinfer-rust-mode.el ends here

0 comments on commit 1feef70

Please sign in to comment.