mirror of
https://github.com/vale981/emacs-jupyter
synced 2025-03-04 15:41:37 -05:00
jupyter-org--coalesce-stream-results: Refactor
This commit is contained in:
parent
bc3b78be43
commit
85f6ff84ed
1 changed files with 14 additions and 22 deletions
|
@ -1596,28 +1596,20 @@ the return value for asynchronous Jupyter source blocks in
|
|||
"Return RESULTS with all contiguous stream results concatenated.
|
||||
All stream results are then turned into fixed-width or
|
||||
example-block elements."
|
||||
(let ((head-to-scalar
|
||||
(lambda (a)
|
||||
;; Convert the head element of A to a scalar if its a
|
||||
;; stream result, return A.
|
||||
(when (jupyter-org--stream-result-p (car a))
|
||||
(setcar a (jupyter-org-scalar
|
||||
(jupyter-org-strip-last-newline
|
||||
(car a)))))
|
||||
a)))
|
||||
(nreverse
|
||||
(funcall
|
||||
head-to-scalar
|
||||
(cl-reduce
|
||||
(lambda (a b)
|
||||
(if (and (jupyter-org--stream-result-p b)
|
||||
(jupyter-org--stream-result-p (car a)))
|
||||
(setcar a (concat (car a) b))
|
||||
(funcall head-to-scalar a)
|
||||
(push b a))
|
||||
a)
|
||||
results
|
||||
:initial-value nil)))))
|
||||
(cl-labels ((scalar (s) (jupyter-org-scalar
|
||||
(jupyter-org-strip-last-newline s))))
|
||||
(let (lst str)
|
||||
(while (consp results)
|
||||
(let ((value (pop results)))
|
||||
(if (jupyter-org--stream-result-p value)
|
||||
(cl-callf concat str value)
|
||||
(when str
|
||||
(push (scalar str) lst)
|
||||
(setq str nil))
|
||||
(push value lst))))
|
||||
(when str
|
||||
(push (scalar str) lst))
|
||||
(nreverse lst))))
|
||||
|
||||
(defun jupyter-org--process-pandoc-results (results)
|
||||
(let* ((results (copy-sequence results))
|
||||
|
|
Loading…
Add table
Reference in a new issue