Function: shortdoc-help-fns-examples-function
shortdoc-help-fns-examples-function is an autoloaded and byte-compiled
function defined in shortdoc.el.gz.
Signature
(shortdoc-help-fns-examples-function FUNCTION)
Documentation
Insert Emacs Lisp examples for FUNCTION into the current buffer.
You can add this function to the help-fns-describe-function-functions
hook to show examples of using FUNCTION in *Help* buffers produced
by C-h f (describe-function).
Probably introduced at or before Emacs version 30.1.
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/shortdoc.el.gz
(defun shortdoc-help-fns-examples-function (function)
"Insert Emacs Lisp examples for FUNCTION into the current buffer.
You can add this function to the `help-fns-describe-function-functions'
hook to show examples of using FUNCTION in *Help* buffers produced
by \\[describe-function]."
(let* ((examples (shortdoc-function-examples function))
(num-examples (length examples))
(times 0))
(dolist (example examples)
(when (zerop times)
(if (> num-examples 1)
(insert "\n Examples:\n\n")
;; Some functions have more than one example per group.
;; Count the number of arrows to know if we need to
;; pluralize "Example".
(let* ((text (cdr example))
(count 0)
(pos 0)
(end (length text))
(double-arrow (if (char-displayable-p ?⇒)
" ⇒"
" =>"))
(double-arrow-example (if (char-displayable-p ?⇒)
" e.g. ⇒"
" e.g. =>"))
(single-arrow (if (char-displayable-p ?→)
" →"
" ->")))
(while (and (< pos end)
(or (string-match double-arrow text pos)
(string-match double-arrow-example text pos)
(string-match single-arrow text pos)))
(setq count (1+ count)
pos (match-end 0)))
(if (> count 1)
(insert "\n Examples:\n\n")
(insert "\n Example:\n\n")))))
(setq times (1+ times))
(insert " ")
(insert (cdr example))
(insert "\n\n"))))