Function: helpful--format-commands

helpful--format-commands is a byte-compiled function defined in helpful.el.

Signature

(helpful--format-commands STR KEYMAP)

Documentation

Replace all the \[ references in STR with buttons.

Source Code

;; Defined in ~/.emacs.d/elpa/helpful-20250408.334/helpful.el
(defun helpful--format-commands (str keymap)
  "Replace all the \\[ references in STR with buttons."
  (replace-regexp-in-string
   ;; Text of the form \\[foo-command]
   (rx "\\[" (group (+ (not (in "]")))) "]")
   (lambda (it)
     (let* ((button-face (if (>= emacs-major-version 28) 'help-key-binding 'button))
            (symbol-name (match-string 1 it))
            (symbol (intern symbol-name))
            (key (where-is-internal symbol keymap t))
            (key-description
             (if key
                 (key-description key)
               (format "M-x %s" symbol-name))))
       (helpful--button
        key-description
        'helpful-describe-exactly-button
        'symbol symbol
        'callable-p t
        'face button-face)))
   str
   t
   t))