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

From: Juri Linkov <[email-masked]>
Date: Mon, 30 Aug 2021 10:33:47 +0300

>> Another question: is it possible not to evaluate :filter in where-is as all?
>
> Then it'd find even less commands, I think?

I thought that maybe it's possible somehow to avoid :filter evaluation
for menus.

>> Yesterday I added to context-menu-map such lines:
>>
>>     (let ((fun (mouse-posn-property (event-start last-input-event)
>>                                     'context-menu-function)))
>>
>> but now noticed that after typing 'C-h m' it fails with:
>>
>> Debugger entered--Lisp error: (args-out-of-range 1786)
>>   mouse-posn-property((#<window 178 on *scratch*> 1786 (0 . 0) 0) context-menu-function)
>>   context-menu-map()
>
> Well, you could just check that last-input-event is a mouse event before
> calling that function?

This patch fixes the error, but still e.g. in Info buffer
typing 'C-h m q' moves point in the Info buffer to some fixed position
(maybe related to a position in *Help* buffer), i.e. still something is wrong.

diff --git a/lisp/mouse.el b/lisp/mouse.el
index 7d3ed9a0e4..f4d7d86c28 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -307,15 +307,19 @@ context-menu-filter-function
 (defun context-menu-map ()
   "Return composite menu map."
   (let ((menu (make-sparse-keymap (propertize "Context Menu" 'hide t))))
-    (let ((fun (mouse-posn-property (event-start last-input-event)
-                                    'context-menu-function)))
+    (let ((fun
+           ;; Check if `where-is-internal' calls this in wrong buffer.
+           (when (eq (window-buffer (posn-window (event-start last-input-event)))
+                     (current-buffer))
+             (mouse-posn-property (event-start last-input-event)
+                                  'context-menu-function))))
       (if (functionp fun)
           (setq menu (funcall fun menu))
         (run-hook-wrapped 'context-menu-functions