Function: nrepl-log--pp-listlike

nrepl-log--pp-listlike is a byte-compiled function defined in nrepl-client.el.

Signature

(nrepl-log--pp-listlike OBJECT &optional FOREGROUND BUTTON)

Documentation

Pretty print nREPL list like OBJECT.

FOREGROUND and BUTTON are as in nrepl-log-pp-object.

Source Code

;; Defined in ~/.emacs.d/elpa/cider-20260414.1619/nrepl-client.el
(defun nrepl-log--pp-listlike (object &optional foreground button)
  "Pretty print nREPL list like OBJECT.
FOREGROUND and BUTTON are as in `nrepl-log-pp-object'."
  (cl-flet ((color (str)
                   (propertize str 'face
                               (append '(:weight ultra-bold)
                                       (when foreground `(:foreground ,foreground))))))
    (let ((head (format "(%s" (car object))))
      (insert (color head))
      (if (null (cdr object))
          (insert ")\n")
        (let* ((indent (+ 2 (- (current-column) (length head))))
               (sorted-pairs (sort (seq-partition (copy-sequence (cdr object)) 2)
                                   (lambda (a b)
                                     (string< (car a) (car b)))))
               (name-lengths (seq-map (lambda (pair) (length (car pair))) sorted-pairs))
               (longest-name (seq-max name-lengths))
               ;; Special entries are displayed first
               (specialq (lambda (pair) (member (car pair) '("id" "op" "session" "time-stamp"))))
               (special-pairs (seq-filter specialq sorted-pairs))
               (not-special-pairs (seq-remove specialq sorted-pairs))
               (all-pairs (seq-concatenate 'list special-pairs not-special-pairs))
               (sorted-object (apply #'seq-concatenate 'list all-pairs)))
          (insert "\n")
          (cl-loop for l on sorted-object by #'cddr
                   do (let ((indent-str (make-string indent ?\s))
                            (name-str (propertize (car l) 'face
                                                  ;; Only highlight top-level keys.
                                                  (unless (eq (car object) 'dict)
                                                    'font-lock-keyword-face)))
                            (spaces-str (make-string (- longest-name (length (car l))) ?\s)))
                        (insert (format "%s%s%s " indent-str name-str spaces-str))
                        (nrepl-log-pp-object (cadr l) nil button)))
          (when (eq (car object) 'dict)
            (delete-char -1))
          (insert (color ")\n")))))))