GNU bug report logs -
#78935
30.1.90; [PATCH] Let Imenu optionally allow duplicate menu entries
Previous Next
Reported by: Drew Adams <drew.adams <at> oracle.com>
Date: Mon, 30 Jun 2025 22:14:01 UTC
Severity: normal
Tags: patch
Found in version 30.1.90
Done: Eli Zaretskii <eliz <at> gnu.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 78935 in the body.
You can then email your comments to 78935 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78935
; Package
emacs
.
(Mon, 30 Jun 2025 22:14:01 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Drew Adams <drew.adams <at> oracle.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Mon, 30 Jun 2025 22:14:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Emacs 29 removed useful behavior from Imenu, producing
backward-incompatible behavior by no longer allowing multiple menu
entries with the same name. Only the first name among duplicates is
used in the menu.
This means that if you're working with a buffer that, for whatever
reason, has multiple definitions of a function, variable etc. - or any
duplication of something else that can be indexed in the menu, you lose
all ability to use the menu to navigate to those entries other than the
first one for a given name.
The attached patch fixes this. It provides a Boolean user option,
`imenu-allow-duplicate-menu-items-flag' to choose the longstanding
pre-29 behavior or the behavior imposed since Emacs 29.
The updated file is also attached, as `imenu-patched.el'.
The only change in the code is to function `imenu--create-keymap',
causing it to respect the new option.
In `imenu--create-keymap' I also replaced the unnecessarily roundabout
(seq-filter #'identity alist) with the more transparent and simpler
(remq nil alist). This change isn't necessary, but it should be
familiar enough to be accepted (and preferred).
I set the default value of the new option to `t', to allow dups by
default. This means a default behavior change from Emacs 29. If that's
unacceptable then change the default option value to `nil'.
And if you don't like the option name (e.g., if you disagree with RMS's
preference that Boolean options have suffix `-flag') then change the
name to whatever you want.
Note that the behavior introduced in Emacs 29 ensures that the key
bindings in the generated keymap (e.g. `imenu--menubar-keymap') have a
symbol as their car. The longstanding pre-29 behavior, which allows
menu entries with the same name, uses a string instead of a symbol,
which works fine but is undocumented behavior. The doc says that a
symbol or a character is used in that place; it doesn't mention that a
string can also be used.
If someone wants to use a different implementation to achieve the same
result, fine. The solution proposed here is simple and
backward-compatibled. It can always be replaced later by some other
implementation that solves the same problem. (E.g., you could use
multiple symbols whose names are _almost_ the same, perhaps by suffixing
the names with <2>, <3>....) I suggest you accept this patch now and
worry later about whether you want to try a different solution. The
solution proposed here has worked for Imenu for 40-some years.
Finally, note that the allowance of duplicates applies only to the use
of an Imenu _menu_ (in the menubar or elsewhere), not also to the use of
command `imenu', which uses `completing-read' to read a menu item.
This is the pre-29 behavior. To have `completing-read' allow duplicate
names requires jumping through some hoops. It's possible, but it isn't
part of this patch. This patch is just to provide both the Emacs
29-30.1 behavior and the pre-29 behavior.
In GNU Emacs 30.1.90 (build 2, x86_64-w64-mingw32) of 2025-05-20 built
on AVALON
Windowing system distributor 'Microsoft Corp.', version 10.0.26100
System Description: Microsoft Windows 10 Pro (v10.0.2009.26100.4061)
Configured using:
'configure --with-modules --without-dbus --with-native-compilation=aot
--without-compress-install --with-tree-sitter CFLAGS=-O2
prefix=/g/rel/install/emacs-30.1.90_1
PKG_CONFIG_PATH=/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig'
Configured features:
ACL GIF GMP GNUTLS HARFBUZZ JPEG LCMS2 LIBXML2 MODULES NATIVE_COMP
NOTIFY W32NOTIFY PDUMPER PNG RSVG SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS TREE_SITTER WEBP XPM ZLIB
(NATIVE_COMP present but libgccjit not available)
Important settings:
value of $LANG: ENU
locale-coding-system: cp1252
[imenu-patch-2025-06-30a.patch (application/octet-stream, attachment)]
[imenu-patched.el (application/octet-stream, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78935
; Package
emacs
.
(Fri, 04 Jul 2025 16:47:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 78935 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Attached is a slightly better patch. The option is
tested at the level of the mapcar, not within the
function arg to mapcar.
Also, the doc string of the new option mentions that
the option applies only to a Imenu menu, not also to
the use of command `imenu', which uses `completing-read'.
The patched version of imenu.el is also attached.
[imenu-patch-2025-07-04a.patch (application/octet-stream, attachment)]
[imenu-patched-2025-07-04a.el (application/octet-stream, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78935
; Package
emacs
.
(Sat, 05 Jul 2025 09:00:03 GMT)
Full text and
rfc822 format available.
Message #11 received at 78935 <at> debbugs.gnu.org (full text, mbox):
> Date: Fri, 4 Jul 2025 16:46:21 +0000
> From: Drew Adams via "Bug reports for GNU Emacs,
> the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
>
> Attached is a slightly better patch. The option is
> tested at the level of the mapcar, not within the
> function arg to mapcar.
>
> Also, the doc string of the new option mentions that
> the option applies only to a Imenu menu, not also to
> the use of command `imenu', which uses `completing-read'.
Thanks.
> +(defcustom imenu-allow-duplicate-menu-items-flag t
> + "Non-nil means that Imenu can include duplicate menu items.
> +For example, if the buffer contains multiple definitions of function
> +`foo' then a menu item is included for each of them.
> +Otherwise, only the first such definition is accessible from the menu.
> +
> +This option applies only to an Imenu menu, not also to the use of
> +command `imenu', which uses `completing-read' to read a menu item.
> +The use of that command doesn't allow duplicate items."
> + :type 'boolean :group 'imenu)
Please add a suitable :version tag.
Also, this new user option should be called out in NEWS.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78935
; Package
emacs
.
(Sat, 05 Jul 2025 16:21:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 78935 <at> debbugs.gnu.org (full text, mbox):
> > Attached is a slightly better patch. The option is
> > tested at the level of the mapcar, not within the
> > function arg to mapcar.
> >
> > Also, the doc string of the new option mentions that
> > the option applies only to a Imenu menu, not also to
> > the use of command `imenu', which uses `completing-read'.
>
> Thanks.
>
> > +(defcustom imenu-allow-duplicate-menu-items-flag t
> > + "Non-nil means that Imenu can include duplicate menu items.
> > +For example, if the buffer contains multiple definitions of function
> > +`foo' then a menu item is included for each of them.
> > +Otherwise, only the first such definition is accessible from the menu.
> > +
> > +This option applies only to an Imenu menu, not also to the use of
> > +command `imenu', which uses `completing-read' to read a menu item.
> > +The use of that command doesn't allow duplicate items."
> > + :type 'boolean :group 'imenu)
>
> Please add a suitable :version tag.
> Also, this new user option should be called out in NEWS.
Thanks for considering the patch.
. Can you tell me what :version to use - would it be "30.2"?
. I'm not familiar with what's needed for NEWS. Can you
let me know what's needed and what form you need it in?
Thx.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78935
; Package
emacs
.
(Sat, 05 Jul 2025 16:46:01 GMT)
Full text and
rfc822 format available.
Message #17 received at 78935 <at> debbugs.gnu.org (full text, mbox):
> From: Drew Adams <drew.adams <at> oracle.com>
> CC: "78935 <at> debbugs.gnu.org" <78935 <at> debbugs.gnu.org>
> Date: Sat, 5 Jul 2025 16:20:39 +0000
>
> > Please add a suitable :version tag.
> > Also, this new user option should be called out in NEWS.
>
> Thanks for considering the patch.
>
> . Can you tell me what :version to use - would it be "30.2"?
No, "31.1", since the change will go to the master branch, which will
become Emacs 31.
> . I'm not familiar with what's needed for NEWS. Can you
> let me know what's needed and what form you need it in?
here's an example, which I hope will explain this. If not, please ask
more specific questions.
*** New user option 'quit-window-kill-buffer'.
This option specifies whether 'quit-window' should preferably kill or
bury the buffer shown by the window to quit.
IOW, the fact there's a new option, and a short description what it
does. In the current case, I'd also state the default value.
Thanks.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78935
; Package
emacs
.
(Sat, 05 Jul 2025 18:27:01 GMT)
Full text and
rfc822 format available.
Message #20 received at 78935 <at> debbugs.gnu.org (full text, mbox):
> > . Can you tell me what :version to use - would it be "30.2"?
>
> No, "31.1", since the change will go to the master branch, which will
> become Emacs 31.
>
> > . I'm not familiar with what's needed for NEWS. Can you
> > let me know what's needed and what form you need it in?
>
> here's an example, which I hope will explain this. If not, please ask
> more specific questions.
>
> *** New user option 'quit-window-kill-buffer'.
> This option specifies whether 'quit-window' should preferably kill or
> bury the buffer shown by the window to quit.
>
> IOW, the fact there's a new option, and a short description what it
> does. In the current case, I'd also state the default value.
>
> Thanks.
Got it. How to I provide the NEWS blurb? Do I need to send
a patch of the 30.1 NEWS file (or the 30.2 pretest 2 NEWS file)?
Or can I just include the blurb in email here, like this?
*** New user option 'imenu-allow-duplicate-menu-items-flag'.
This specifies whether Imenu can include duplicate menu items.
Duplicate items are allowed by default (option value 't').
Also, do you prefer that `-flag' be removed from the name?
It seems that Emacs no longer respects that convention.
Either way is OK by me.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78935
; Package
emacs
.
(Sun, 06 Jul 2025 04:40:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 78935 <at> debbugs.gnu.org (full text, mbox):
> From: Drew Adams <drew.adams <at> oracle.com>
> CC: "78935 <at> debbugs.gnu.org" <78935 <at> debbugs.gnu.org>
> Date: Sat, 5 Jul 2025 18:26:35 +0000
>
> > *** New user option 'quit-window-kill-buffer'.
> > This option specifies whether 'quit-window' should preferably kill or
> > bury the buffer shown by the window to quit.
> >
> > IOW, the fact there's a new option, and a short description what it
> > does. In the current case, I'd also state the default value.
> >
> > Thanks.
>
> Got it. How to I provide the NEWS blurb? Do I need to send
> a patch of the 30.1 NEWS file (or the 30.2 pretest 2 NEWS file)?
>
> Or can I just include the blurb in email here, like this?
It is best if you could download NEWS from the master branch, and
produce a patch for that. Failing that, the entry itself would do.
> *** New user option 'imenu-allow-duplicate-menu-items-flag'.
> This specifies whether Imenu can include duplicate menu items.
> Duplicate items are allowed by default (option value 't').
>
> Also, do you prefer that `-flag' be removed from the name?
Yes, please.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78935
; Package
emacs
.
(Sun, 06 Jul 2025 15:04:02 GMT)
Full text and
rfc822 format available.
Message #26 received at 78935 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
> It is best if you could download NEWS from the master branch, and
> produce a patch for that. Failing that, the entry itself would do.
I don't know how to do that - dunno where it's available
for download using a browser. Here is the NEWS entry:
*** New user option 'imenu-allow-duplicate-menu-items'.
This specifies whether Imenu can include duplicate menu items.
Duplicate items are allowed by default (option value 't').
> > Also, do you prefer that `-flag' be removed from the name?
> Yes, please.
Done. See attached imenu.el patch and patched file.
Thx.
[imenu-patch-2025-07-06a.patch (application/octet-stream, attachment)]
[imenu-patched-2025-07-06a.el (application/octet-stream, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78935
; Package
emacs
.
(Sun, 06 Jul 2025 15:39:01 GMT)
Full text and
rfc822 format available.
Message #29 received at 78935 <at> debbugs.gnu.org (full text, mbox):
> From: Drew Adams <drew.adams <at> oracle.com>
> CC: "78935 <at> debbugs.gnu.org" <78935 <at> debbugs.gnu.org>
> Date: Sun, 6 Jul 2025 15:03:13 +0000
>
> > It is best if you could download NEWS from the master branch, and
> > produce a patch for that. Failing that, the entry itself would do.
>
> I don't know how to do that - dunno where it's available
> for download using a browser.
Here:
https://cgit.git.savannah.gnu.org/cgit/emacs.git/tree/
> Here is the NEWS entry:
>
> *** New user option 'imenu-allow-duplicate-menu-items'.
> This specifies whether Imenu can include duplicate menu items.
> Duplicate items are allowed by default (option value 't').
>
> > > Also, do you prefer that `-flag' be removed from the name?
> > Yes, please.
>
> Done. See attached imenu.el patch and patched file.
Thanks.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78935
; Package
emacs
.
(Mon, 07 Jul 2025 16:09:02 GMT)
Full text and
rfc822 format available.
Message #32 received at 78935 <at> debbugs.gnu.org (full text, mbox):
> > > It is best if you could download NEWS from the master branch, and
> > > produce a patch for that. Failing that, the entry itself would do.
> > I don't know how to do that - dunno where it's available
> > for download using a browser.
>
> Here:
>
> https://cgit.git.savannah.gnu.org/cgit/emacs.git/tree/
OK, thanks for next time. You have what's needed for
this time, right?
(But that site seems _very_ slow to load and to access
subdirs there.)
> > Done. See attached imenu.el patch and patched file.
>
> Thanks.
Let me know, if you need something else.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78935
; Package
emacs
.
(Mon, 07 Jul 2025 16:15:02 GMT)
Full text and
rfc822 format available.
Message #35 received at 78935 <at> debbugs.gnu.org (full text, mbox):
> From: Drew Adams <drew.adams <at> oracle.com>
> CC: "78935 <at> debbugs.gnu.org" <78935 <at> debbugs.gnu.org>
> Date: Mon, 7 Jul 2025 16:08:42 +0000
>
> > > > It is best if you could download NEWS from the master branch, and
> > > > produce a patch for that. Failing that, the entry itself would do.
> > > I don't know how to do that - dunno where it's available
> > > for download using a browser.
> >
> > Here:
> >
> > https://cgit.git.savannah.gnu.org/cgit/emacs.git/tree/
>
> OK, thanks for next time. You have what's needed for
> this time, right?
Yes.
> (But that site seems _very_ slow to load and to access
> subdirs there.)
I think that's intentional, because all kinds of bots and crawlers
could otherwise bring Savannah to its knees.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78935
; Package
emacs
.
(Mon, 07 Jul 2025 16:17:02 GMT)
Full text and
rfc822 format available.
Message #38 received at 78935 <at> debbugs.gnu.org (full text, mbox):
> > (But that site seems _very_ slow to load and to access
> > subdirs there.)
>
> I think that's intentional, because all kinds of bots and crawlers
> could otherwise bring Savannah to its knees.
Good to hear (unfortunately). Thx.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78935
; Package
emacs
.
(Sat, 12 Jul 2025 08:16:02 GMT)
Full text and
rfc822 format available.
Message #41 received at 78935 <at> debbugs.gnu.org (full text, mbox):
> From: Drew Adams <drew.adams <at> oracle.com>
> CC: "78935 <at> debbugs.gnu.org" <78935 <at> debbugs.gnu.org>
> Date: Sun, 6 Jul 2025 15:03:13 +0000
>
> > > Also, do you prefer that `-flag' be removed from the name?
> > Yes, please.
>
> Done. See attached imenu.el patch and patched file.
I was about to install the patch, but it triggers a compilation
warning:
ELC imenu.elc
In end of data:
imenu.el:522:25: Warning: the function `increment-symbol-name' is not known to be defined.
I guess something is missing from the patch?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#78935
; Package
emacs
.
(Sat, 12 Jul 2025 17:18:02 GMT)
Full text and
rfc822 format available.
Message #44 received at 78935 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
> > Done. See attached imenu.el patch and patched file.
>
> I was about to install the patch, but it triggers a compilation
> warning:
>
> ELC imenu.elc
>
> In end of data:
> imenu.el:522:25: Warning: the function `increment-symbol-name' is not
> known to be defined.
>
> I guess something is missing from the patch?
Ouch! Really sorry for that. Thank goodness for that
warning and that you noticed it.
The correct files are attached here. Let me know, if
see another problem.
[imenu-patch-2025-07-12a.patch (application/octet-stream, attachment)]
[imenu-patched-2025-07-12a.el (application/octet-stream, attachment)]
Reply sent
to
Eli Zaretskii <eliz <at> gnu.org>
:
You have taken responsibility.
(Sun, 13 Jul 2025 05:45:02 GMT)
Full text and
rfc822 format available.
Notification sent
to
Drew Adams <drew.adams <at> oracle.com>
:
bug acknowledged by developer.
(Sun, 13 Jul 2025 05:45:02 GMT)
Full text and
rfc822 format available.
Message #49 received at 78935-done <at> debbugs.gnu.org (full text, mbox):
> From: Drew Adams <drew.adams <at> oracle.com>
> CC: "78935 <at> debbugs.gnu.org" <78935 <at> debbugs.gnu.org>
> Date: Sat, 12 Jul 2025 17:17:36 +0000
>
> > > Done. See attached imenu.el patch and patched file.
> >
> > I was about to install the patch, but it triggers a compilation
> > warning:
> >
> > ELC imenu.elc
> >
> > In end of data:
> > imenu.el:522:25: Warning: the function `increment-symbol-name' is not
> > known to be defined.
> >
> > I guess something is missing from the patch?
>
> Ouch! Really sorry for that. Thank goodness for that
> warning and that you noticed it.
>
> The correct files are attached here. Let me know, if
> see another problem.
Thanks, now installed on the master branch, and closing the bug.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sun, 10 Aug 2025 11:24:06 GMT)
Full text and
rfc822 format available.
This bug report was last modified 26 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.