Subject: bug#61436: Emacs Freezing With Java Files

From: Alan Mackenzie <[email-masked]>
Date: Sun, 22 Oct 2023 14:15:08 +0000

Hello, Mats.

On Sun, Oct 22, 2023 at 00:14:43 +0200, Mats Lidell wrote:
> Hi Alan,

> Sorry for coming back late to this issue but today I tried to use the
> suggested regexp and got into some problems doing that.

Sorry about that.

> > Alan Mackenzie writes:
> > Here's the regexp.  Would people please try it out and let me know how
> > well it works.  
> >
> > (defconst java-defun-prompt-regexp
> >   (let ((space* "[ \t\n\r\f]*")
> >         (space+ "[ \t\n\r\f]+")
> >         (modifier*
> >          (concat "\\(?:"
> >                  (regexp-opt '("abstract" "const" "default" "final" "native"
> >                                "private" "protected" "public" "static"
> >                                "strictfp" "synchronized" "threadsafe"
> >                                "transient" "volatile")
> >                              'words)    ; Compatible with XEmacs
> >                  space+ "\\)*"))
> >         (ids-with-dots "[_$a-zA-Z][_$.a-zA-Z0-9]*")
> >         (ids-with-dot-\[\] "[[_$a-zA-Z][][_$.a-zA-Z0-9]*")
> >         (paren-exp "([^);{}]*)")
> >         (generic-exp "<[^(){};]*>"))
> >     (concat "^[ \t]*"
> >             modifier*
> >             "\\(?:" generic-exp space* "\\)?"
> >             ids-with-dot-\[\] space+                ; first part of type
> >             "\\(?:" ids-with-dot-\[\] space+ "\\)?" ; optional second part of type.
> >             "\\(?:[_a-zA-Z][^][ \t:;.,{}()=<>]*"    ; defun name
> >                 "\\|" ids-with-dot*
> >             "\\)" space*
> >             paren-exp
> >             "\\(?:" space* "]\\)*"      ; What's this for?
> >             "\\(?:" space* "\\<throws\\>" space* ids-with-dot-\[\]s*
> >                   "\\(?:," space* ids-with-dot-\[\]s* "\\)*"
> >             "\\)?"
> >             space*)))

> Can there be some typos in there or missing lines? I get a compiler warning
> for space+ being used in the let, should it be a let*? ids-with-dots is
> reported as not used. Can it be meant to be ids-with-dot*?
> ids-with-dot-\[\]s* is undefined!?

No, the regexp just wasn't tested right.  I made the mistake in
"testing" it of having all the things like space+ already defined as
defconsts.  So I failed to pick up the let which should have been let*
and giving all the uses of the bound variables their actual names.  :-(

Can I ask you to delete that buggy version and try the following
instead?  Thanks!

(defconst java-defun-prompt-regexp
  (let* ((space* "[ \t\n\r\f]*")
         (space+ "[ \t\n\r\f]+")
         (modifier*
          (concat "\\(?:"
                  (regexp-opt '("abstract" "const" "default" "final" "native"
                                "private" "protected" "public" "static"
                                "strictfp" "synchronized" "threadsafe"
                                "transient" "volatile")
                              'words)   ; Compatible with XEmacs
                  space+ "\\)*"))
         (ids-with-dots "[_$a-zA-Z][_$.a-zA-Z0-9]*")
         (ids-with-dot-\[\] "[[_$a-zA-Z][][_$.a-zA-Z0-9]*")
         (paren-exp "([^);{}]*)")
         (generic-exp "<[^(){};]*>"))
    (concat "^[ \t]*"
            modifier*
            "\\(?:" generic-exp space* "\\)?"
            ids-with-dot-\[\] space+                ; first part of type
            "\\(?:" ids-with-dot-\[\] space+ "\\)?" ; optional second part of type.
            "\\(?:[_a-zA-Z][^][ \t:;.,{}()=<>]*"    ; defun name
                "\\|" ids-with-dots
            "\\)" space*
            paren-exp
            "\\(?:" space* "]\\)*"      ; What's this for?
            "\\(?:" space* "\\<throws\\>" space* ids-with-dot-\[\]
                  "\\(?:," space* ids-with-dot-\[\] "\\)*"
            "\\)?"
            space*)))

> Yours
> -- 
> %% Mats

-- 
Alan Mackenzie (Nuremberg, Germany).