Function: which-key--maybe-add-docstring

which-key--maybe-add-docstring is a byte-compiled function defined in which-key.el.gz.

Signature

(which-key--maybe-add-docstring CURRENT ORIGINAL)

Documentation

Maybe concat a docstring to CURRENT and return result.

Specifically, do this if ORIGINAL is a command with a docstring and which-key-show-docstrings is non-nil. If which-key-show-docstrings is the symbol docstring-only, just return the docstring.

Source Code

;; Defined in /usr/src/emacs/lisp/which-key.el.gz
(defun which-key--maybe-add-docstring (current original)
  "Maybe concat a docstring to CURRENT and return result.
Specifically, do this if ORIGINAL is a command with a docstring
and `which-key-show-docstrings' is non-nil.  If
`which-key-show-docstrings' is the symbol docstring-only, just
return the docstring."
  (let* ((orig-sym (intern original))
         (doc (when (commandp orig-sym)
                (documentation orig-sym)))
         (doc (when doc
                (replace-regexp-in-string
                 (concat "^\\(?::"
                         (regexp-opt '("around" "override"
                                       "after" "after-until" "after-while"
                                       "before" "before-until" "before-while"
                                       "filter-args" "filter-return"))
                         " advice: [^\n]+\n"
                         "\\)+\n")
                 "" doc)))
         (docstring (when doc
                      (which-key--propertize (car (split-string doc "\n"))
                                             'face 'which-key-docstring-face))))
    (cond ((not (and which-key-show-docstrings docstring))
           current)
          ((eq which-key-show-docstrings 'docstring-only)
           docstring)
          (t
           (format "%s %s" current docstring)))))