Subject: bug#61436: Emacs Freezing With Java Files

From: Hank Greenburg <[email-masked]>
Date: Sun, 12 Feb 2023 00:24:49 +0000

To follow up on this, somehow disabling which-function-mode from my config has solved the problem. That doesn't make sense though because I didn't add that until after it had frozen in the first place. I know that for certain because I had to use IntelliJ and got the idea for using which-function-mode from IntelliJ.

To clarify, this froze every single time I tried to edit the file no matter what modes I had turned on or off. It happened at least 40 times in total and never once was I able to actually edit the file within Emacs. After disabling which-function-mode though I have restarted Emacs a few times, written in the file, scrolled though it all without a single hiccup.

So my problem is seemingly solved but there is an underlying bug somewhere that I'm not really able to isolate aside from disabling which-function-mode.

------- Original Message -------
On Saturday, February 11th, 2023 at 12:16 PM, Hank Greenburg via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <[email-masked]> wrote:

> I have a few Java files that are about 500 lines of code and I can't move around in them much before Emacs freezes. I first thought it was java-lsp but it still happened after disabling and uninstalling it. I also uninstalled lsp-mode as well, but that didn't change anything.
>
> I started doing CPU profiles of it and found that which-function-mode was taking up 67% of my CPU usage. While this is happening all I was doing was holding the down arrow until it froze about 350 lines in. Didn't press any other buttons.
>
> So I disabled which-function-mode and moved around the buffer just fine! Though when trying to edit the file (just hit enter), it froze again. This time it seems like electric-indent-mode was taking up close to 50% of my CPU usage.
>
> I disabled that and tried again and then it froze again with c-indent-line-or-region eating up 63% of my CPU when I use TAB.
>
> While using debug-on-quit I get the below output. Any idea what's happening here and how it can be addressed? I do know though that if I launch emacs with the -Q argument, then there aren't any problems at all. I tried large files of other types and it only seems to happen with Java files. I attached screenshots of the CPU profiler outputs for each of the three scenarios. Attached is also the Java file as well as my init file.
>
> I am using emacs version 28.2 on EndeavorOS, but reproduced the results using both emacs 29 and the master branch.
>
> Debugger entered--Lisp error: (quit)
> beginning-of-defun()
> c-get-fallback-scan-pos(17794)
> c-parse-state-get-strategy(17794 1)
> c-parse-state-1()
> c-parse-state()
> c-guess-basic-syntax()
> c-indent-line()
> #f(compiled-function () (interactive nil) #<bytecode 0x180248dcca1cc57e>)()
> c-indent-command(nil)
> c-indent-line-or-region(nil nil)
> funcall-interactively(c-indent-line-or-region nil nil)
> call-interactively(c-indent-line-or-region nil nil) command-execute(c-indent-line-or-region)