Function: pp

pp is an autoloaded and byte-compiled function defined in pp.el.gz.

Signature

(pp OBJECT &optional STREAM)

Documentation

Output the pretty-printed representation of OBJECT, any Lisp object.

Quoting characters are printed as needed to make output that read can handle, whenever this is possible.

Uses the pretty-printing code specified in pp-default-function.

Output stream is STREAM, or value of standard-output (which see).

View in manual

Probably introduced at or before Emacs version 19.20.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/pp.el.gz
;;;###autoload
(defun pp (object &optional stream)
  "Output the pretty-printed representation of OBJECT, any Lisp object.
Quoting characters are printed as needed to make output that `read'
can handle, whenever this is possible.

Uses the pretty-printing code specified in `pp-default-function'.

Output stream is STREAM, or value of `standard-output' (which see)."
  (let ((stream (or stream standard-output)))
    (cond
     ((and (eq stream (current-buffer))
           ;; Make sure the current buffer is setup sanely.
           (eq (syntax-table) emacs-lisp-mode-syntax-table)
           (eq indent-line-function #'lisp-indent-line))
      ;; Skip the buffer->string->buffer middle man.
      (funcall pp-default-function object)
      ;; Preserve old behavior of (usually) finishing with a newline.
      (unless (bolp) (insert "\n")))
     (t
      (save-current-buffer
        (when (bufferp stream) (set-buffer stream))
        (let ((begin (point))
              (cols (current-column)))
          (princ (pp-to-string object) (or stream standard-output))
          (when (and (> cols 0) (bufferp stream))
            (indent-rigidly begin (point) cols))))))))