Subject: bug#9923: 24.0.91; `where-is' does not find recentf menu items (cmds, not files)

From: Stefan Monnier <[email-masked]>
Date: Thu, 26 Aug 2021 13:44:24 -0400

Lars Ingebrigtsen [2021-08-26 15:42:54] wrote:
> Stefan Monnier <[email-masked]> writes:
>> So IIRC `where-is` instead uses the "unfiltered" binding.  So you can
>> often get what you want by being careful about the BINDING you put into
>> `(menu-item "foo" BINDING :filter ...).
>
> Hm...  but in this case, the filter returns all the items:
>
>     (easy-menu-add-item
>      (recentf-menu-bar) recentf-menu-path
>      (list recentf-menu-title :filter 'recentf-make-menu-items)
>      recentf-menu-before)))

I think the problem is that it's not the same filter: there's the
`:filter` above which is part of the easymenu syntax and there the
`:filter` in the `menu-item` syntax.

Easymenu does indeed use the menu-item-:filter to implement the
easymenu-:filter but IIRC easymenu uses a menu item of the form

    (menu-item TITLE MENU :filter ...)

where MENU is the actual menu in its original easymenu-syntax form (aka
XEmacs syntax), and it's converted to the keymap-syntax by the :filter.

That would explain why `where-is` can't find any commands in MENU since
`where-is` expects it to use a keymap-syntax rather than an easymenu-syntax.

The relevant code is in `easy-menu-create-menu`:

        (pcase keyword
          (:filter
           (setq filter (lambda (menu)
                          (easy-menu-filter-return (funcall arg menu)
                                                   menu-name))))

as well as:

                     ;; The filter expects the menu in its XEmacs form and the
                     ;; pre-filter form will only be passed to the filter
                     ;; anyway, so we'd better not convert it at all (it will
                     ;; be converted on the fly by easy-menu-filter-return).
                     menu-items
                   (append menu (mapcar #'easy-menu-convert-item menu-items))))

So maybe the comment is wrong (I can't vouch for the guy who wrote it
anyway), and we should put the pre-converted menu in there, and then the
filter function should simply ignore its `menu` argument and use the
`menu-items` instead (or something like that).

Such a change could break something somewhere, tho: AFAICT currently,
just like the menu-item-:filter, the easymenu-:filter doesn't have to be
accompanied with a "menu" in proper syntax but it is required only to
return a menu in proper syntax, so the format of `menu-items` is
actually private to the :filter (tho in practice it's usually a valid
menu).

        Stefan