Subject: 29.0.50; imenu with imenu-use-popup-menu fails for *Rescan* item

From: Visuwesh <[email-masked]>
Date: Fri, 24 Jun 2022 17:18:59 +0530

When imenu-use-popup-menu is non-nil and one selects the *Rescan* item,
imenu fails with the following backtrace,

    Debugger entered--Lisp error: (error "Invalid `key-parse' syntax: %S" ["*Rescan*"])
      lookup-key((keymap "sh" ("*Rescan*" "*Rescan*" . #f(compiled-function () (interactive nil) #<bytecode -0x1823bf90e9c446ac>)) ("x" "x" . #f(compiled-function () (interactive nil) #<bytecode -0x19fbbb6b7dca5348>)) ("y" "y" . #f(compiled-function () (interactive nil) #<bytecode -0x19fbbb6b7da17348>))) ["*Rescan*"])
      popup-menu((keymap "sh" ("*Rescan*" "*Rescan*" . #f(compiled-function () (interactive nil) #<bytecode -0x1823bf90e9c446ac>)) ("x" "x" . #f(compiled-function () (interactive nil) #<bytecode -0x19fbbb6b7dca5348>)) ("y" "y" . #f(compiled-function () (interactive nil) #<bytecode -0x19fbbb6b7da17348>))) 105)
      imenu--mouse-menu((("*Rescan*" . -99) ("x" . #<marker at 1 in sh>) ("y" . #<marker at 7 in sh>)) 105)
      imenu-choose-buffer-index()
      byte-code("\300 C\207" [imenu-choose-buffer-index] 1)
      call-interactively(imenu nil nil)
      command-execute(imenu)

Sometimes, this is also observed with an item other than *Rescan*:

    Debugger entered--Lisp error: (error "Invalid `key-parse' syntax: %S" ["x (def)"])
      lookup-key((keymap "sh" ("*Rescan*" "*Rescan*" . #f(compiled-function () (interactive nil) #<bytecode -0x1823bf90e9c446ac>)) ("x (def)" "x (def)" . #f(compiled-function () (interactive nil) #<bytecode -0x19471a772db71348>)) ("y (def)" "y (def)" . #f(compiled-function () (interactive nil) #<bytecode -0x194701872ad91348>))) ["x (def)"])
      popup-menu((keymap "sh" ("*Rescan*" "*Rescan*" . #f(compiled-function () (interactive nil) #<bytecode -0x1823bf90e9c446ac>)) ("x (def)" "x (def)" . #f(compiled-function () (interactive nil) #<bytecode -0x19471a772db71348>)) ("y (def)" "y (def)" . #f(compiled-function () (interactive nil) #<bytecode -0x194701872ad91348>))) 105)
      imenu--mouse-menu((("*Rescan*" . -99) ("x (def)" . #<marker at 1 in sh>) ("y (def)" . #<marker at 24 in sh>)) 105)
      imenu-choose-buffer-index()
      byte-code("\300 C\207" [imenu-choose-buffer-index] 1)
      call-interactively(imenu nil nil)
      command-execute(imenu)

this is in a python-mode buffer containing the following text,

    def x():
        return y

    def y():
        return x

No such problem is seen when adding the index to the menubar using M-x
imenu-add-menubar-index however.

In GNU Emacs 29.0.50 (build 19, x86_64-pc-linux-gnu, X toolkit, Xaw scroll bars)
 of 2022-06-21 built on astatine
Repository revision: be35c92c90d455739a6ff9d4beefa2b35d044852
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101003
System Description: Debian GNU/Linux 11 (bullseye)

Configured using:
 'configure --with-modules --with-sound=alsa --with-x-toolkit=lucid
 --with-json --without-xaw3d --without-gconf --without-libsystemd
 --with-x --without-cairo'

Configured features:
ACL DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG JSON
LIBOTF LIBSELINUX LIBXML2 MODULES NOTIFY INOTIFY PDUMPER PNG RSVG
SECCOMP SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS WEBP X11 XDBE XFT
XIM XINPUT2 XPM LUCID ZLIB

Important settings:
  value of $LC_MONETARY: ta_IN.UTF-8
  value of $LC_NUMERIC: ta_IN.UTF-8
  value of $LANG: en_GB.UTF-8
  locale-coding-system: utf-8-unix

Major mode: ELisp/l

Minor modes in effect:
  reveal-mode: t
  shell-dirtrack-mode: t
  outline-minor-mode: t
  recentf-mode: t
  paredit-mode: t
  eros-mode: t
  flymake-mode: t
  pdf-occur-global-minor-mode: t
  hl-todo-mode: t
  minibuffer-depth-indicate-mode: t
  repeat-mode: t
  display-time-mode: t
  display-battery-mode: t
  winner-mode: t
  delete-selection-mode: t
  straight-use-package-mode: t
  straight-package-neutering-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tab-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  undelete-frame-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  abbrev-mode: t

Load-path shadows:
None found.

Features:
(shadow flyspell ispell ecomplete emacsbug bug-reference gnus-fun
dired-aux pulse display-line-numbers ement-room-list ement
taxy-magit-section taxy ement-notify ement-room ewoc color ement-api
ement-structs ement-macros plz dns ts sort gnus-cite flow-fill
mm-archive mail-extr textsec uni-scripts idna-mapping ucs-normalize
uni-confusable textsec-check gnus-async gnus-bcklg qp gnus-ml
expand-region subword-mode-expansions text-mode-expansions
cc-mode-expansions the-org-mode-expansions er-basic-expansions
expand-region-core expand-region-custom cap-words superword subword
nix-mode nix-repl nix-shell nix-store magit-section nix-instantiate
nix-shebang nix-format nix gnus-dired face-remap find-dired skeleton
smerge-mode log-edit add-log cl-print rfc2104 tramp-cmds tramp-cache
tramp-sh tramp tramp-loaddefs trampver tramp-integration cus-start
files-x tramp-compat ls-lisp shortdoc help-fns radix-tree time-stamp
reveal dabbrev calccomp calc-alg calc-vec calc-aent calc-yank calc-ext
calc-misc calc-menu calc calc-loaddefs rect calc-macs shell-command+
misc notifications misearch multi-isearch org-capture doct ob-C cc-mode
cc-fonts cc-guess cc-menus cc-cmds cc-styles cc-align cc-engine cc-vars
cc-defs ob-shell shell ob-racket async ob-async cdlatex texmathp ol-eww
eww xdg url-queue mm-url ol-rmail ol-mhe ol-irc ol-info ol-gnus nnselect
ol-docview doc-view ol-bibtex ol-bbdb ol-w3m ol-doi org-link-doi
org-tempo tempo org-id org-refile ol-man org ob ob-tangle ob-ref ob-lob
ob-table ob-exp org-macro org-footnote org-src ob-comint org-pcomplete
pcomplete org-list org-faces org-entities org-version ob-emacs-lisp
ob-core ob-eval org-table oc-basic bibtex ol org-keys oc org-compat
org-macs org-loaddefs flymake-shellcheck sh-script smie executable ffap
noutline outline lua-mode cursor-sensor recentf tree-widget vc-backup
log-view pcvs-util vc diff vc-git diff-mode vc-dispatcher network-stream
nsm nndraft nnmh nnfolder nnmaildir nnagent nnml nnnil gnus-agent
gnus-srvr gnus-score score-mode nnvirtual gnus-msg gnus-art mm-uu
mml2015 mm-view mml-smime smime gnutls dig nntp gnus-cache gnus-sum shr
pixel-fill kinsoku url-file url-dired svg dom gnus-group gnus-undo
gnus-start gnus-dbus gnus-cloud nnimap nnmail mail-source utf7 netrc
nnoo parse-time iso8601 gnus-spec gnus-int gnus-range message sendmail
yank-media rmc puny rfc822 mml mml-sec epa epg rfc6068 epg-config
mm-decode mm-bodies mm-encode mail-parse rfc2231 rfc2047 rfc2045
ietf-drums mailabbrev gmm-utils mailheader gnus-win gnus nnheader
gnus-util mail-utils range mm-util mail-prsvr server paredit edmacro
kmacro eros time-date checkdoc lisp-mnt flymake-proc flymake project
warnings thingatpt wordel-autoloads sokoban-autoloads ement-autoloads
ts-autoloads svg-lib-autoloads taxy-magit-section-autoloads
taxy-autoloads plz-autoloads nov-autoloads esxml-autoloads kv-autoloads
transmission-autoloads lua-mode-autoloads nix-mode-autoloads
magit-section-autoloads dash-autoloads racket-mode-autoloads
eros-autoloads flymake-shellcheck-autoloads writegood-mode-autoloads
siege-mode-autoloads paredit-autoloads puni-autoloads
expand-region-autoloads filladapt-autoloads compose quail
scroll-other-window org-pdftools-autoloads org-noter-autoloads
change-env-autoloads math-delimiters-autoloads doct-autoloads
ob-async-autoloads async-autoloads emacs-ob-racket-autoloads
valign-autoloads cdlatex-autoloads auctex-autoloads tex-site pdf-occur
ibuf-ext ibuffer ibuffer-loaddefs tablist advice tablist-filter
semantic/wisent/comp semantic/wisent semantic/wisent/wisent
semantic/util-modes semantic/util semantic semantic/tag semantic/lex
semantic/fw mode-local cedet pdf-isearch let-alist pdf-misc imenu
pdf-tools package browse-url url url-proxy url-privacy url-expand
url-methods url-history url-cookie generate-lisp-file url-domsuf
url-util mailcap url-handlers url-parse auth-source eieio eieio-core
eieio-loaddefs json map url-vars compile comint ansi-color cus-edit
hl-todo edebug debug backtrace find-func wid-edit pdf-view
password-cache jka-compr pdf-cache pdf-info tq pdf-util pdf-macs
image-mode dired-x dired dired-loaddefs exif pdf-tools-autoloads
tablist-autoloads mb-depth repeat visual-fill-autoloads
olivetti-autoloads hl-todo-autoloads time format-spec battery dbus
filenotify xml disp-table lacarte-autoloads shell-command-plus-autoloads
winner derived delsel cus-load easy-mmode avy ring avy-autoloads
vc-backup-autoloads icalendar diary-lib diary-loaddefs cal-menu calendar
cal-loaddefs rx filecache flymake-grammarly-autoloads
grammarly-autoloads websocket-autoloads finder-inf request-autoloads
s-autoloads chemtable-autoloads molar-mass-autoloads saveplace-pdf-view
saveplace bookmark text-property-search pp saveplace-pdf-view-autoloads
pcase straight-autoloads info cl-seq cl-extra help-mode seq byte-opt
straight subr-x cl-macs gv cl-loaddefs cl-lib bytecomp byte-compile
cconv vz-nh-theme vz-options-theme iso-transl tooltip eldoc paren
electric uniquify ediff-hook vc-hooks lisp-float-type elisp-mode mwheel
term/x-win x-win term/common-win x-dnd tool-bar dnd fontset image
regexp-opt fringe tabulated-list replace newcomment text-mode lisp-mode
prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu
timer select scroll-bar mouse jit-lock font-lock syntax font-core
term/tty-colors frame minibuffer nadvice simple cl-generic indonesian
philippine cham georgian utf-8-lang misc-lang vietnamese tibetan thai
tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian
slovak czech european ethiopic indian cyrillic chinese composite
emoji-zwj charscript charprop case-table epa-hook jka-cmpr-hook help
abbrev obarray oclosure cl-preloaded button loaddefs faces cus-face
macroexp files window text-properties overlay sha1 md5 base64 format env
code-pages mule custom widget keymap hashtable-print-readable backquote
threads dbusbind inotify dynamic-setting system-font-setting
font-render-setting x-toolkit xinput2 x multi-tty make-network-process
emacs)

Memory information:
((conses 16 798175 167210) (symbols ?0 42938 6) (strings 32 204427 20385) (string-bytes 1 6986157) (vectors 16 112407) (vector-slots 8 2281491 85224) (floats 8 763 521) (intervals ?8 30822 1973) (buffers 992 ??))