Function: context-menu-map

context-menu-map is a byte-compiled function defined in mouse.el.gz.

Signature

(context-menu-map &optional CLICK)

Documentation

Return menu map constructed for context near mouse CLICK.

The menu is populated by calling functions from context-menu-functions. Each function receives the menu and the mouse click event and returns the same menu after adding own menu items to the composite menu. When there is a text property context-menu-function at CLICK, it overrides all functions from context-menu-functions. At the end, it's possible to modify the final menu by specifying the function context-menu-filter-function.

Source Code

;; Defined in /usr/src/emacs/lisp/mouse.el.gz
(defun context-menu-map (&optional click)
  "Return menu map constructed for context near mouse CLICK.
The menu is populated by calling functions from `context-menu-functions'.
Each function receives the menu and the mouse click event
and returns the same menu after adding own menu items to the composite menu.
When there is a text property `context-menu-function' at CLICK,
it overrides all functions from `context-menu-functions'.
At the end, it's possible to modify the final menu by specifying
the function `context-menu-filter-function'."
  (let* ((menu (make-sparse-keymap (propertize "Context Menu" 'hide t)))
         (click (or click last-input-event))
         (fun (mouse-posn-property (event-start click)
                                   'context-menu-function)))

    (if (functionp fun)
        (setq menu (funcall fun menu click))
      (run-hook-wrapped 'context-menu-functions
                        (lambda (fun)
                          (setq menu (funcall fun menu click))
                          nil)))

    ;; Remove duplicate separators
    (let ((l menu))
      (while (consp l)
        (when (and (equal (cdr-safe (car l)) menu-bar-separator)
                   (equal (cdr-safe (cadr l)) menu-bar-separator))
          (setcdr l (cddr l)))
        (setq l (cdr l))))

    (when (functionp context-menu-filter-function)
      (setq menu (funcall context-menu-filter-function menu click)))
    menu))