Function: minor-mode-menu-from-indicator

minor-mode-menu-from-indicator is an interactive and byte-compiled function defined in mouse.el.gz.

Signature

(minor-mode-menu-from-indicator INDICATOR &optional WINDOW EVENT)

Documentation

Show menu for minor mode specified by INDICATOR.

INDICATOR is either a string object returned by posn-object or the car of such an object. WINDOW may be the window whose mode line is being displayed.

EVENT may be the mouse event that is causing this menu to be displayed.

Interactively, INDICATOR is read using completion. If there is no menu defined for the minor mode, then create one with items Turn Off and Help.

Probably introduced at or before Emacs version 27.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/mouse.el.gz
;; Provide a mode-specific menu on a mouse button.

(defun minor-mode-menu-from-indicator (indicator &optional window event)
  "Show menu for minor mode specified by INDICATOR.

INDICATOR is either a string object returned by `posn-object' or
the car of such an object.  WINDOW may be the window whose mode
line is being displayed.

EVENT may be the mouse event that is causing this menu to be
displayed.

Interactively, INDICATOR is read using completion.
If there is no menu defined for the minor mode, then create one with
items `Turn Off' and `Help'."
  (interactive
   (list (completing-read
	  "Minor mode indicator: "
	  (describe-minor-mode-completion-table-for-indicator))))
  ;; If INDICATOR is a string object, WINDOW is set, and
  ;; `mode-line-compact' might be enabled, find a string in
  ;; `minor-mode-alist' that is present within the INDICATOR and whose
  ;; extents within INDICATOR contain the position of the object
  ;; within the string.
  (when window
    (catch 'found
      (with-selected-window window
        (let ((alist minor-mode-alist) string position)
          (when (and (consp indicator) mode-line-compact)
            (with-temp-buffer
              (insert (car indicator))
              (dolist (menu alist)
                ;; If this is a valid minor mode menu entry,
                (when (and (consp menu)
                           (setq string (format-mode-line (cadr menu)
                                                          nil window))
                           (> (length string) 0))
                  ;; Start searching for an appearance of (cdr menu).
                  (goto-char (point-min))
                  (while (search-forward string nil 0)
                    ;; If the position of the string object is
                    ;; contained within, set indicator to the minor
                    ;; mode in question.
                    (setq position (1+ (cdr indicator)))
                    (and (>= position (match-beginning 0))
                         (<= position (match-end 0))
                         (setq indicator (car menu))
                         (throw 'found nil)))))))))))
  ;; If INDICATOR is still a cons, use its car.
  (when (consp indicator)
    (setq indicator (car indicator)))
  (let* ((minor-mode (if (symbolp indicator)
                         ;; indicator being set to a symbol means that
                         ;; the loop above has already found a
                         ;; matching minor mode.
                         indicator
                       (lookup-minor-mode-from-indicator indicator)))
         (mm-fun (or (get minor-mode :minor-mode-function) minor-mode)))
    (unless minor-mode (error "Cannot find minor mode for `%s'" indicator))
    (let* ((map (cdr-safe (assq minor-mode minor-mode-map-alist)))
           (menu (and (keymapp map) (lookup-key map [menu-bar]))))
      (setq menu
            (if menu
                (mouse-menu-non-singleton menu)
              (if (fboundp mm-fun)      ; bug#20201
                  `(keymap
                    ,(format "%s - %s" indicator
			     (capitalize
			      (string-replace
			       "-" " " (format "%S" minor-mode))))
                    (turn-off menu-item "Turn off minor mode" ,mm-fun)
                    (help menu-item "Help for minor mode"
                          ,(lambda () (interactive)
                             (describe-function mm-fun)))))))
      (if menu
          (popup-menu menu event)
        (message "No menu available")))))