Subject: Re: bug#78612: imenu list generation failing on some items of similar quality

From: Eli Zaretskii <[email-masked]>
Date: Wed, 28 May 2025 15:08:42 +0300

> Date: Tue, 27 May 2025 17:54:05 +0000
> From:  mdnorton via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <[email-masked]>
> 
> * Emacs version: 30.1
> * GNU Emacs 30.1 (build 2, x86_64-w64-mingw32) of 2025-02-23
> * Windows OS
> 
> What I'm seeing is a failure in imenu​ to create a correct list for function names using the MATLAB package
> (https://github.com/mathworks/Emacs-MATLAB-Mode/).  I've been working with the current maintainer and I
> am pretty certain that this is not directly a MATLAB package issue, though I cannot tell if it is an interaction. 
> The regular expression to identify the function name that is the point of the imenu​ list is pretty gnarly but
> seems to work with the corner cases required for the syntax.  
> 
> In any event, this is the behavior I see that doesn't make a lot of sense to me.  Given a MATLAB file with the
> following contents:
> 
> % -----------------------------------------------
> function foobar1(a, b, c)
> end
> 
> function foobar2(a, b, c)
> end
> 
> function gen_pulse_avg_lin_data(a, b, c)
> end
> 
> function gen_pulse_avg_log_data(a, b, c)
> end
> 
> function gen_beamsharpened_data(a, b, c)
> end
> 
> function foobar3(a, b, c)
> end
> % --------------------------------------------------------
> 
> As presented, imenu​ will fail and only list the last 3 functions.

I cannot reproduce this: in my testing imenu finds all of the
functions in this file.  But since you haven't presented a complete
recipe for reproducing the problem, I cannot be sure I did the same as
you do.

Here's what I did:

  emacs -Q
  M-: (add-to-list 'load-path "/path/to/Emacs-MATLAB-Mode/") RET
  M-x load-file RET /path/to/Emacs-MATLAB-Mode/matlab-autoload.el RET
  C-x C-f testimenu.m RET
  M-x imenu RET foobar3 RET
  M-x imenu-add-menubar-index RET
  Click mouse on the menubar's Imenu item

(where testimenu.m is the file with the contents you posted above).
At this point I see all the functions in the file in the menu that
Emacs drops down.

If you run the same recipe as I did, do you still see the problem?