unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: rswgnu@gmail.com
Cc: Hank Greenburg <hank.greenburg@protonmail.com>,
	Mats Lidell <mats.lidell@lidells.se>,
	acm@muc.de, Eli Zaretskii <eliz@gnu.org>,
	Jens Schmidt <jschmidt4gnu@vodafonemail.de>,
	61436@debbugs.gnu.org
Subject: bug#61436: Emacs Freezing With Java Files
Date: Wed, 17 Apr 2024 18:50:33 +0000	[thread overview]
Message-ID: <ZiAZ-euAJpFFUz2w@ACM> (raw)
In-Reply-To: <Zh_JagP5xaaXJMOo@ACM>

Hello again, Bob.

On Wed, Apr 17, 2024 at 13:06:50 +0000, Alan Mackenzie wrote:
> On Tue, Apr 16, 2024 at 21:35:59 -0400, Robert Weiner wrote:
> >    Hi Alan:
> >    I just re-read this whole thread and realized you resolved the problem
> >    for the Java defun-prompt-regexp but not the C++
> >    defun-prompt-regexp in Hyperbole's hui-select.el:L404 (probably were
> >    just tired after all of that).
> >    Today, someone else reported that the C++ regexp was hanging their
> >    Emacs.  Do you think you could pick this back up and rework the C++
> >    regexp as you did the Java one?  It would be a big help; otherwise, I
> >    think we'll just have to disable that functionality in Hyperbole.
> >    Best regards,
> >    Bob
> >    On Sun, Oct 22, 2023 at 1:18â¯PM Mats Lidell
> >    <[1]mats.lidell@lidells.se> wrote:

> Yes, I'll happily finish off that C++ regexp.  I made considerable
> progress with it back in October, getting smething basically working but
> with some rough edges.  One problem is that the regexp was ~1600
> characters long.  I don't know if this might make the program slow -
> possibly not.

> I've found the .el file I was working in, and located my notes from
> October.  It's going to take longer than a day or two, but hopefully
> less than a week or two.

It was rather easier than I'd anticipated.  There is my first attempt
below.  It should find most C++ defun starts, but not all.  In particlar
it won't recognise one with nested parens or nested template delimiters;
regexps cannot handle arbitrary nesting,and it didn't seem worth the
trouble to code in a small bounded degree of nesting, though this surely
could be done if I'm wrong, here.

The regexp is not small.  At the latest count it was 2,223 characters
long.  I hope this won't affect performance too much.

Please try out this regexp, and let me know how well it's working.
Thanks!

> [ .... ]



(defconst c++-defun-prompt-regexp
  (let*
      ((space* "[ \t\n\r\f]*")
       (space+ "[ \t\n\r\f]+")
       (ad-hoc-requires-clause
	(concat "\\(?:requires" space* "[][()<> \t\n\r\f_$a-zA-Z0-9&|\"'+=.,*:~-]+" space* "\\)?"))
       (id (concat "[_$~a-zA-Z][_$a-zA-Z0-9]*")
	   ;; (concat "\\(\\(~" space* "\\)?" "\\([_$a-zA-Z][_$a-zA-Z0-9]*\\)\\)")
	   )
       (template-brackets "\\(?:<[^;{}]*>\\)")
       (id-<> (concat id "\\(?:" space* template-brackets "\\)?"))
       (id-:: (concat id-<> "\\(?:" space* "::" space* id-<> "\\)*"))
       (paren-exp "([^{};]*)")
       (template-exp\? (concat "\\(?:template" space* template-brackets space* "\\)?"))
       (type-prefix-modifier* (concat "\\(?:\\(?:"
				      "\\(?:\\<extern" space+ "\"[^\"]+\"\\)"
				      "\\|"
				      (regexp-opt '("auto" "const" "explicit" "extern"
						    "friend" "inline" "mutable"
						    "noexcept" "overload"
						    "register" "static" "typedef"
						    "virtual" "volatile")
						  'words)
				      "\\)"
				      space+
				      "\\)*"))
       (type-exp (concat
		  "\\(?:\\(?:" template-brackets space* "\\)?"
		  type-prefix-modifier*
		  "\\(?:\\(?:decltype" space* paren-exp space* "\\)"
		  "\\|"
		  "\\(?:"
		  "\\(?:class\\|enum\\|struct\\|typename\\|union\\)"
		  "\\(?:" space* "\\.\\.\\.\\)?\\)"
		  space+ id space*
		  "\\(?::" id-:: space* "\\)?"
		  "\\|"
		  id-:: space*
		  "\\)"
		  "\\)\\{1,2\\}"))
       (type-mid-modifier* (concat "\\(?:"
				   (regexp-opt
				    '("auto" "consteval" "constexpr"
				      "constinit" "explicit"
				      "extern" "friend" "inline"
				      "mutable" "noexcept" "register"
				      "static" "template"
				      "thread_local" "throw"
				      "virtual" "volatile")
				    'words)
				   space+ "\\)*"))
       (operator-exp (concat "\\(?:operator\\>" space*
			     "\\(?:[][a-z_+*/%^?&|!~<>,:=-]+"
			     "\\|()\\|\"\""
			     "\\)" space*
			     "\\)"))

       (name-exp			; matches foo or (* foo), etc.
	(concat "\\(?:(" space* "[*&]+" space* id-:: space* "[][()]*" ")"
		"\\|\\(?:[*&]+" space* "\\)?" id-::
		"\\)" space*))
       (type-suffix-modifier* (concat "\\(?:"
				      (regexp-opt
				       '("auto" "const" "noexcept"
					 "requires" "throw" "volatile")
				       'words)
				      space+ "\\)*"))
       (post-paren-modifier* (concat "\\(?:"
				     (regexp-opt
				      '("const" "final" "override"
					"mutable")
				      'words)
				     space* "\\)*")))

    (concat template-exp\?
	    "\\(?:" ad-hoc-requires-clause "\\)?"
	    type-exp
	    type-mid-modifier*
	    "\\(?:" operator-exp "\\|" name-exp "\\)"
	    type-suffix-modifier*
	    paren-exp space*
	    "\\(?:->" space* type-exp "\\)?"
	    post-paren-modifier*
	    "{"))


-- 
Alan Mackenzie (Nuremberg, Germany).





  parent reply	other threads:[~2024-04-17 18:50 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-11 18:16 bug#61436: Emacs Freezing With Java Files Hank Greenburg via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-12  0:24 ` Hank Greenburg via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-12  6:30   ` Eli Zaretskii
2023-02-12 16:52     ` Hank Greenburg via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-12 17:05       ` Eli Zaretskii
2023-02-12 17:11         ` Hank Greenburg via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-09 20:26           ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-10 20:58             ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-11  7:28               ` Mats Lidell via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-11 10:17                 ` Robert Weiner
2023-10-11 19:38                   ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-11 20:07                     ` Robert Weiner
2023-10-11 21:43                     ` Mats Lidell via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-11 22:03                     ` Alan Mackenzie
2023-10-12 19:58                       ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-13 12:41                         ` Alan Mackenzie
2023-10-13 18:02                           ` Mats Lidell via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-13 20:42                           ` Jens Schmidt via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-14 19:41                             ` Alan Mackenzie
2023-10-15 10:20                               ` Robert Weiner
2023-10-16 14:05                                 ` Alan Mackenzie
2023-10-16 19:10                                   ` Robert Weiner
2023-10-21 22:14                                   ` Mats Lidell via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-22 14:15                                     ` Alan Mackenzie
2023-10-22 17:17                                       ` Mats Lidell via Bug reports for GNU Emacs, the Swiss army knife of text editors
     [not found]                                         ` <CA+OMD9hgM_NX7GmeW8ph5fBW6SkFGogf4W4JOO5o62H3X15WHw@mail.gmail.com>
2024-04-17 13:22                                           ` Alan Mackenzie
     [not found]                                           ` <Zh_JagP5xaaXJMOo@ACM>
2024-04-17 18:50                                             ` Alan Mackenzie [this message]
2024-04-17 22:24                                               ` Robert Weiner
2024-04-19  2:19                                               ` Robert Weiner
2024-04-19  4:40                                                 ` Robert Weiner
2024-04-19 15:59                                                   ` Alan Mackenzie
2024-04-19  2:58                           ` Robert Weiner
2023-02-12  6:00 ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZiAZ-euAJpFFUz2w@ACM \
    --to=acm@muc.de \
    --cc=61436@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=hank.greenburg@protonmail.com \
    --cc=jschmidt4gnu@vodafonemail.de \
    --cc=mats.lidell@lidells.se \
    --cc=rswgnu@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).