Function: which-key-mode

which-key-mode is an autoloaded, interactive and byte-compiled function defined in which-key.el.gz.

Signature

(which-key-mode &optional ARG)

Documentation

Toggle which-key-mode(var)/which-key-mode(fun).

which-key is a minor mode that displays the key bindings following your currently entered incomplete command (a prefix) in a popup.

For example, after enabling the minor mode, if you enter \C-x and wait for one second (by default), the minibuffer will expand with all available key bindings that follow \C-x (or as many as space allows given your settings).

This is a global minor mode. If called interactively, toggle the Which-Key mode mode. If the prefix argument is positive, enable the mode, and if it is zero or negative, disable the mode.

If called from Lisp, toggle the mode if ARG is toggle. Enable the mode if ARG is nil, omitted, or is a positive number. Disable the mode if ARG is a negative number.

To check whether the minor mode is enabled in the current buffer, evaluate (default-value \=which-key-mode)'.

The mode's hook is called both when the mode is enabled and when it is disabled.

Probably introduced at or before Emacs version 30.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/which-key.el.gz
;;; Mode

;;;###autoload
(define-minor-mode which-key-mode
  "Toggle `which-key-mode'.

`which-key' is a minor mode that displays the key bindings following
your currently entered incomplete command (a prefix) in a popup.

For example, after enabling the minor mode, if you enter \\`C-x' and
wait for one second (by default), the minibuffer will expand with all
available key bindings that follow \\`C-x' (or as many as space allows
given your settings)."
  :global t
  :group 'which-key
  :lighter which-key-lighter
  :keymap (let ((map (make-sparse-keymap)))
            (mapc
             (lambda (prefix)
               (define-key map
                 (kbd (concat prefix " " which-key-paging-key))
                 #'which-key-C-h-dispatch))
             which-key-paging-prefixes)
            map)
  (if which-key-mode
      (progn
        (setq which-key--echo-keystrokes-backup echo-keystrokes)
        (when (or (eq which-key-show-prefix 'echo)
                  (eq which-key-popup-type 'minibuffer))
          (which-key--setup-echo-keystrokes))
        (unless (member prefix-help-command which-key--paging-functions)
          (setq which-key--prefix-help-cmd-backup prefix-help-command))
        (when (or which-key-use-C-h-commands
                  which-key-show-early-on-C-h)
          (setq prefix-help-command #'which-key-C-h-dispatch))
        (when which-key-show-remaining-keys
          (add-hook 'pre-command-hook #'which-key--lighter-restore))
        (add-hook 'pre-command-hook #'which-key--hide-popup)
        (add-hook 'window-size-change-functions
                  #'which-key--hide-popup-on-frame-size-change)
        (which-key--start-timer))
    (setq echo-keystrokes which-key--echo-keystrokes-backup)
    (when which-key--prefix-help-cmd-backup
      (setq prefix-help-command which-key--prefix-help-cmd-backup))
    (when which-key-show-remaining-keys
      (remove-hook 'pre-command-hook #'which-key--lighter-restore))
    (remove-hook 'pre-command-hook #'which-key--hide-popup)
    (remove-hook 'window-size-change-functions
                 #'which-key--hide-popup-on-frame-size-change)
    (which-key--stop-timer)))