Function: cl--print-table

cl--print-table is a byte-compiled function defined in cl-extra.el.gz.

Signature

(cl--print-table HEADER ROWS &optional LAST-SLOT-ON-NEXT-LINE)

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/cl-extra.el.gz
(defun cl--print-table (header rows &optional last-slot-on-next-line)
  ;; FIXME: Isn't this functionality already implemented elsewhere?
  (let ((cols (apply #'vector (mapcar #'string-width header)))
        (col-space 2))
    (dolist (row rows)
      (dotimes (i (length cols))
        (let* ((x (pop row))
               (curwidth (aref cols i))
               (newwidth (if x (string-width x) 0)))
          (if (> newwidth curwidth)
              (setf (aref cols i) newwidth)))))
    (let ((formats '())
          (col 0))
      (dotimes (i (length cols))
        (push (concat (propertize "	"
                                  'display
                                  `(space :align-to ,(+ col col-space)))
                      "%s")
              formats)
        (incf col (+ col-space (aref cols i))))
      (let ((format (mapconcat #'identity (nreverse formats))))
        (insert (apply #'format format
                       (mapcar (lambda (str) (propertize str 'face 'italic))
                               header))
                "\n")
        (insert (apply #'format format
                       (mapcar (lambda (str) (make-string (string-width str) ?—))
                               header))
                "\n")
        (dolist (row rows)
          (insert (apply #'format format row) "\n")
          (when last-slot-on-next-line
            (dolist (line (string-lines (car (last row))))
              (insert "    " line "\n"))
            (insert "\n")))))))