>>> Mind however that many of these commands are also meant to operate from >>> the mode line lighters, in which case this is precisely the desired >>> behavior. >> >> I see that such events show they originate from 'mode-line', >> and events from the menu bar contain 'menu-bar'. So maybe >> it would be sufficient to filter out 'mode-line' and 'menu-bar'. > > Instead of checking 'posn-area', much simpler would be to implement this > only for the context-menu with a new option similar to 'mouse-yank-at-point'. > > +(defcustom context-menu-move-point nil > + "If non-nil, move point to the mouse click before opening context menu." > + :type 'boolean > + :version "30.1") This turned out to be quite useless. Because it's too annoying when a command that operates on the whole buffer moves point to a random place where the mouse happened to be clicked. This means there is a need to distinguish commands for which the context is the whole buffer from the commands where context is narrowed to the clicked position. Two examples: 1. 'outline-hide-body' hides body lines in the whole buffer, thus should be declared with context of the buffer: ``` (defun outline-hide-body () "Hide all body lines in buffer, leaving all headings visible. Note that this does not hide the lines preceding the first heading line." (declare (context buffer)) (interactive) (outline-hide-region-body (point-min) (point-max))) ``` 2. 'outline-hide-entry' hides body after the clicked heading, so should be declared with context of point: ``` (defun outline-hide-entry () "Hide the body directly following this heading." (declare (context point)) (interactive) (save-excursion (outline-back-to-heading) (outline-end-of-heading) (outline-flag-region (point) (progn (outline-next-preface) (point)) t))) ``` Here is a draft that works surprisingly well: