Next: , Previous: , Up: Documentation   [Index]


3.5.6 documentation example

See (elisp)Access to Documentation Strings for an example of using these functions in ELisp code.

Here is an example of using the two functions, documentation and documentation-property, to display the documentation strings for several symbols in a Help buffer.

 1  (defun describe-symbols (pattern)
 2    "Describe the Emacs Lisp symbols matching PATTERN.
 3  All symbols that have PATTERN in their name are described
 4  in the *Help* buffer."
 5    (interactive "sDescribe symbols matching: ")
 6    (let ((describe-func
 7           (lambda (s)
 8             ;; Print description of symbol.
 9             (if (fboundp s)             ; It is a function.
10                 (princ
11                  (format "%s\t%s\n%s\n\n" s
12                    (if (commandp s)
13                        (let ((keys (where-is-internal s)))
14                          (if keys
15                              (concat
16                               "Keys: "
17                               (mapconcat 'key-description
18                                          keys " "))
19                            "Keys: none"))
20                      "Function")
21                    (or (documentation s)
22                        "not documented"))))
23  
24             (if (boundp s)              ; It is a variable.
25                 (princ
26                  (format "%s\t%s\n%s\n\n" s
27                    (if (custom-variable-p s)
28                        "Option " "Variable")
29                    (or (documentation-property
30                          s 'variable-documentation)
31                        "not documented"))))))
32          sym-list)
33  
34      ;; Build a list of symbols that match pattern.
35      (mapatoms (lambda (sym)
36                  (if (string-match pattern (symbol-name sym))
37                      (setq sym-list (cons sym sym-list)))))
38  
39      ;; Display the data.
40      (help-setup-xref (list 'describe-symbols pattern) (interactive-p))
41      (with-help-window (help-buffer)
42        (mapcar describe-func (sort sym-list 'string<)))))

Listing 3.1: Definition of @code{describe-symbols}