Function: cl--describe-class

cl--describe-class is a byte-compiled function defined in cl-extra.el.gz.

Signature

(cl--describe-class TYPE &optional CLASS)

Aliases

eieio-help-class (obsolete since 25.1)

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/cl-extra.el.gz
(defun cl--describe-class (type &optional class)
  (unless class (setq class (cl--find-class type)))
  (let ((location (find-lisp-object-file-name type 'define-type))
        (metatype (type-of class)))
    (insert (symbol-name type)
            (substitute-command-keys " is a type (of kind `"))
    (help-insert-xref-button (symbol-name metatype)
                             'cl-help-type metatype)
    (insert (substitute-command-keys "')"))
    (when location
      (insert (substitute-command-keys " in `"))
      (help-insert-xref-button
       (help-fns-short-filename location)
       'cl-type-definition type location 'define-type)
      (insert (substitute-quotes "'")))
    (insert ".\n")

    ;; Parents.
    (let ((pl (cl--class-parents class))
          cur)
      (when pl
        (insert " Inherits from ")
        (while (setq cur (pop pl))
          (setq cur (cl--class-name cur))
          (insert (substitute-quotes "`"))
          (help-insert-xref-button (symbol-name cur)
                                   'cl-help-type cur)
          (insert (substitute-command-keys (if pl "', " "'"))))
        (insert ".\n")))

    ;; Children, if available.  ¡For EIEIO!
    (let ((ch (condition-case nil
                  (cl-struct-slot-value metatype 'children class)
                (cl-struct-unknown-slot nil)))
          cur)
      (when ch
        (insert " Children ")
        (while (setq cur (pop ch))
          (insert (substitute-quotes "`"))
          (help-insert-xref-button (symbol-name cur)
                                   'cl-help-type cur)
          (insert (substitute-command-keys (if ch "', " "'"))))
        (insert ".\n")))

    ;; Type's documentation.
    (let ((doc (cl--class-docstring class)))
      (when doc
        (insert "\n" doc "\n\n")))

    ;; Describe all the slots in this class.
    (cl--describe-class-slots class)

    ;; Describe all the methods specific to this class.
    (let ((generics (cl-generic-all-functions type)))
      (when generics
        (insert (propertize "Specialized Methods:\n\n" 'face 'bold))
        (dolist (generic generics)
          (insert (substitute-quotes "`"))
          (help-insert-xref-button (symbol-name generic)
                                   'help-function generic)
          (insert (substitute-quotes "'"))
          (pcase-dolist (`(,qualifiers ,args ,doc)
                         (cl--generic-method-documentation generic type))
            (insert (format " %s%S\n" qualifiers args)
                    (or doc "")))
          (insert "\n\n"))))))