40ants / 40ants/cl-prevalence

sexp.lisp: Option to insert line breaks.

Đang mở
#5 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Common Lisp
Star
34
Fork
7
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Instead of outputting everything on one line, it's be nice to leave some customization options to the users so that they can decide when to insert line breaks.

For instance:

```lisp
(export '*one-element-per-line*)
(defvar *one-element-per-line* nil
"If non-nil, print one element per line in sequence types.")

(defun maybe-newline (stream)
(when *one-element-per-line*
(write-char #\newline stream)))

(defmethod serialize-sexp-internal ((object sequence) stream serialization-state)
"Like the original `serialize-sexp-internal' but uses `*one-element-per-line* to "
(flet ((proper-sequence (length)
(let ((id (set-known-object serialization-state object)))
(write-string "(:SEQUENCE " stream)
(prin1 id stream)
(write-string " :CLASS " stream)
(print-symbol (etypecase object (list 'list) (vector 'vector)) stream)
(write-string " :SIZE " stream)
(prin1 length stream)
(unless (zerop length)
(write-string " :ELEMENTS (" stream)
(maybe-newline stream)
(map nil
#'(lambda (element)
(write-string " " stream)
(serialize-sexp-internal element stream serialization-state)
(maybe-newline stream))
object))
(write-string " ) )" stream)))
(improper-list ()
(let ((id (set-known-object serialization-state object)))
(write-string "(:CONS " stream)
(prin1 id stream)
(write-char #\Space stream)
(serialize-sexp-internal (car object) stream serialization-state)
(write-char #\Space stream)
(serialize-sexp-internal (cdr object) stream serialization-state)
(write-string " ) " stream))))
(let ((id (known-object-id serialization-state object)))
(if id
(progn
(write-string "(:REF . " stream)
(prin1 id stream)
(write-string ")" stream))
(multiple-value-bind (seq-type length) (sequence-type-and-length object)
(ecase seq-type
((:proper-sequence :proper-list) (proper-sequence length))
((:dotted-list :circular-list) (improper-list))))))))
```

The above function is like the original except for the `maybe-newline` calls.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.