Function: mode-line--make-lighter-menu

mode-line--make-lighter-menu is a byte-compiled function defined in bindings.el.gz.

Signature

(mode-line--make-lighter-menu ALIST)

Documentation

Return a menu keymap for minor mode lighters in ALIST.

ALIST should be in the same format as minor-mode-alist.

Return nil if no lighters in ALIST should be visible, for example, there are no active minor modes or non-empty lighters.

Source Code

;; Defined in /usr/src/emacs/lisp/bindings.el.gz
(defun mode-line--make-lighter-menu (alist)
  "Return a menu keymap for minor mode lighters in ALIST.
ALIST should be in the same format as `minor-mode-alist'.

Return nil if no lighters in ALIST should be visible, for example, there
are no active minor modes or non-empty lighters."
  (let ((menu (make-sparse-keymap "Minor Modes"))
        (empty t))
    (dolist (item alist)
      (when-let* ((variable (car item))
                  ((and (boundp variable)
                        (symbol-value variable)))
                  (lighter (format-mode-line `("" ,@(cdr-safe item))))
                  ((not (string= lighter "")))
                  (toggle (or (get variable :minor-mode-function) variable))
                  ;; Follow the format in `mouse-minor-mode-menu'
                  (name (format "%s - %s" lighter
                                (capitalize
                                 (string-replace
                                  "-" " " (symbol-name toggle))))))
        (when (eq ?  (aref name 0))
          (setq name (substring name 1)))
        (let* ((map (cdr-safe (assq variable minor-mode-map-alist)))
               (mm-menu (and (keymapp map)
                             (keymap-lookup map "<menu-bar>"))))
          (setq mm-menu
                (cond (mm-menu (mouse-menu-non-singleton mm-menu))
                      ((fboundp toggle)
                       (define-keymap :name name
                         "<help>" (list 'menu-item
                                        "Help for minor mode"
                                        (lambda () (interactive)
                                          (describe-function toggle)))
                         "<turn-off>" (list 'menu-item
                                            "Turn off minor mode"
                                            toggle)))
                      ;; No menu and not a minor mode function, so just
                      ;; display the label without a sub-menu.
                      (t nil)))
          (keymap-set menu (format "<%s>" toggle)
                      (list 'menu-item name mm-menu))
          (setq empty nil))))
    (and (not empty) menu)))