justinbarclay / parinfer-rust-mode

Simplifying how you write Lisp
https://shaunlebron.github.io/parinfer/
GNU General Public License v3.0
227 stars 16 forks source link

Defer load seems causing problems on switching buffers #81

Closed braineo closed 5 months ago

braineo commented 5 months ago

after 01bfb781af605ff93097df4bec6e2687ffe9a962

I started to get when i have a mini-buffer open (use M-x to bring up consult)

Error during redisplay: (parinfer-rust--defer-loading #<window 3 on init.el>) signaled (excessive-lisp-nesting 1601)
The following modes may cause issues with parinfer-rust, do you want to disable them? Mode(s): electric-pair-mode? (y or n) y
(use-package parinfer-rust-mode
  :if (string-match-p "MODULES" system-configuration-features)
  :hook
  ((emacs-lisp-mode scheme-mode) . (lambda (
   (progn
    (electric-pair-local-mode -1)
    (parinfer-rust-mode)))))

the problem is gone after removing these added lines

-   (parinfer-rust-enabled
-    (parinfer-rust-mode-disable))
-   ((not (eq (current-buffer)
-             (window-buffer (selected-window))))
-    (add-hook 'window-selection-change-functions #'parinfer-rust--defer-loading nil t))

the window-selection-change-functions seems to be an AOE affecting many things. i suspect every time my consult opens it makes emacs into a infinite loop on calling the defer load function

justinbarclay commented 5 months ago

Hey thanks for reporting this bug and narrowing to down to a potential issue.

I also use consult and haven't ran into this bug. Is it M-x in general that causes this or a specific command?

additionally, can you try setting these two variables and see if it resolves the issue for you

   (setq parinfer-rust-disable-troublesome-modes t)
   (setq parinfer-rust-check-before-enable 'defer)
justinbarclay commented 5 months ago

Follow up question, which package manager do you use? package.el? straight? elpaca?

I ask because I was able to replicate a very similar behavior in a very specific situation - using elpaca and being asked to download parinfer-rust. If I said no, I would get repeatedly asked to install it. However, if I already had the library installed Emacs behaves normally with elpaca.

If I use package.el I never run into this situation.

braineo commented 5 months ago

Follow up question, which package manager do you use? package.el? straight? elpaca?

I ask because I was able to replicate a very similar behavior in a very specific situation - using elpaca and being asked to download parinfer-rust. If I said no, I would get repeatedly asked to install it. However, if I already had the library installed Emacs behaves normally with elpaca.

If I use package.el I never run into this situation.

hmm i use use-package

https://github.com/braineo/fate-emacs/blob/master/modules/fate-langs.el#L36-L49

but i do think i saw the prompt once for downloading parinfer-rust and i hit y to install it

let me see if i can get more print on what's going on there

braineo commented 5 months ago

Follow up question, which package manager do you use? package.el? straight? elpaca? I ask because I was able to replicate a very similar behavior in a very specific situation - using elpaca and being asked to download parinfer-rust. If I said no, I would get repeatedly asked to install it. However, if I already had the library installed Emacs behaves normally with elpaca. If I use package.el I never run into this situation.

hmm i use use-package

https://github.com/braineo/fate-emacs/blob/master/modules/fate-langs.el#L36-L49

but i do think i saw the prompt once for downloading parinfer-rust and i hit y to install it

let me see if i can get more print on what's going on there

(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)))
+   (print (format "try to enable parinfer in %s" (buffer-name)))
    (remove-hook 'window-selection-change-functions #'parinfer-rust--defer-loading t)
    (parinfer-rust-mode)))

i added this line and this is what happened i opened a file treesit.el.gz, then i run any command that can bring up a minibuffer (consult, projectile, etc. does not matter which one)

this is what i got (at this point i cannot copy and paste from emacs, it died pretty much :(

starting from minibuf-1, the parinfer-mode seemed to keep calling itself? in mini buffer, which it should not.

what comes to the last is the buffer i need parinfer running (treesit.el.gz)

image

justinbarclay commented 5 months ago

Hey, thanks for the help debugging this.

I think I have a fix on the branch fix-recursion. If you want to test this out and see if it fixes the problem for you, that would be cool. If not, I'll be testing this some more tomorrow and hopefully releasing it tomorrow night. https://github.com/justinbarclay/parinfer-rust-mode/pull/82

braineo commented 5 months ago

thanks for the very prompt fix! it seems my problem goes away with the fix.

Manueljlin commented 4 months ago

fixed it for me too, thank you <3