Skip to content

Commit

Permalink
Fix potential recursive parinfer-rust-mode call
Browse files Browse the repository at this point in the history
  • Loading branch information
justinbarclay committed Apr 14, 2024
1 parent f8caae8 commit 5b95a1f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 31 deletions.
2 changes: 1 addition & 1 deletion parinfer-rust-helper.el
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ mode to better emulate users."
(when (eq (current-buffer)
(window-buffer (selected-window)))
(remove-hook 'window-selection-change-functions #'parinfer-rust--defer-loading t)
(parinfer-rust-mode)))
(parinfer-rust-mode-enable)))
;; Disable fill column warning only for this buffer to enable long strings of text without
;; having to do a weird mapconcat.
;; Local Variables:
Expand Down
60 changes: 32 additions & 28 deletions parinfer-rust-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ Checks if MODE is a valid Parinfer mode, and uses
(parinfer-rust--set-default-state)
(parinfer-rust--dim-parens))

(defun parinfer-rust-mode-enable ()
(defun parinfer-rust-mode-setup ()
"Enable Parinfer."
(setq-local parinfer-rust-enabled t)
(parinfer-rust--detect-troublesome-modes)
Expand Down Expand Up @@ -535,6 +535,35 @@ This includes stopping tracking of all changes."
(setq-local parinfer-rust--disable nil)
(setq-local parinfer-rust--disable t)))

(defun parinfer-rust-mode-enable ()
"Enable Parinfer."
;; 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-setup)
(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)))))

;;;###autoload
(defun parinfer-rust-switch-mode ()
"Switch to a different Parinfer mode.
Expand Down Expand Up @@ -572,37 +601,12 @@ not available."
(cond
(parinfer-rust-enabled
(parinfer-rust-mode-disable))
;; Don't do anything if the buffer is not selected
((not (eq (current-buffer)
(window-buffer (selected-window))))
(add-hook 'window-selection-change-functions #'parinfer-rust--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))))))))
(parinfer-rust-mode-enable))))

(provide 'parinfer-rust-mode)
;;; parinfer-rust-mode.el ends here
3 changes: 1 addition & 2 deletions test/test-helper.el
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,9 @@ it makes no sense to convert it to a string using
parinfer-rust-library
parinfer-rust--lib-name)
(indent-tabs-mode 0)
(parinfer-rust-mode-enable)
;; Disable checks for deferral and do not run --execute on initialization
;; this breaks a lot of test because they expect the buffer to be in a specific state
)))
(parinfer-rust-mode-setup))))

(defun simulate-parinfer-in-another-buffer--without-changes (test-string mode)
"Run parinfer on buffer using text and cursor position
Expand Down

0 comments on commit 5b95a1f

Please sign in to comment.