jupyter-org--wrap-result-maybe: Use cond

This commit is contained in:
Nathaniel Nicandro 2018-11-30 23:41:05 -06:00
parent d269f00036
commit c218c976e3
No known key found for this signature in database
GPG key ID: C34814B309DD06B8

View file

@ -656,35 +656,33 @@ new \"scalar\" result with the result of calling
(forward-line (- post)) (forward-line (- post))
(line-beginning-position)))) (line-beginning-position))))
;;;; Wrapping results in a drawer
(defun jupyter-org--wrap-result-maybe (context result) (defun jupyter-org--wrap-result-maybe (context result)
"Depending on CONTEXT, wrap RESULT in a drawer." "Depending on CONTEXT, wrap RESULT in a greater org element if needed.
Cleanup the buffer if needed."
;; If CONTEXT is a keyword, then it is the #+RESULTS: line which means RESULT ;; If CONTEXT is a keyword, then it is the #+RESULTS: line which means RESULT
;; is the first result being inserted. ;; is the first result being inserted.
(let ((first-result (eq (org-element-type context) 'keyword))) (let* ((first-result (eq (org-element-type context) 'keyword))
(if first-result (new-result (cond
(if (or (and (stringp result) ;; First result that can be removed by
;; Org tables are returned as strings by this time. So we need ;; `org-babel-remove-result' without being wrapped in a
;; something to distinguish them from regular strings. See ;; drawer
;; `jupyter-org-scalar'. ((and first-result (jupyter-org-babel-result-p result)) result)
(get-text-property 0 'org-table result)) ;; First result that needs to be wrapped in a drawer
(memq (org-element-type result) (first-result (jupyter-org-results-drawer result))
'(example-block ;; The second result, which means CONTEXT is the first.
export-block fixed-width item ;; Wrap both of them in a drawer
plain-list src-block table))) (t
;; No need to wrap result types that can be recognized by (prog1 (jupyter-org-results-drawer context result)
;; `org-babel-remove-result' ;; Ensure that a #+RESULTS: line is not prepended to
result ;; context when calling `org-element-interpret-data'
(jupyter-org-results-drawer result)) (org-element-put-property context :results nil)
;; If this is not the first result, then it is a result that is being ;; Ensure there is no post-blank since
;; appended to the current results. This means CONTEXT was the first ;; `org-element-interpret-data' already normalizes the
;; result and we need to wrap both CONTEXT and RESULT in a drawer. ;; string
(prog1 (jupyter-org-results-drawer context result) (org-element-put-property context :post-blank nil))))))
;; Ensure that a #+RESULTS: line is not prepended to context when new-result))
;; calling `org-element-interpret-data'
(org-element-put-property context :results nil)
;; Ensure there is no post-blank since
;; `org-element-interpret-data' already normalizes the string
(org-element-put-property context :post-blank nil)))))
(defun jupyter-org--display-latex (limit) (defun jupyter-org--display-latex (limit)
"Show inline latex fragments between LIMIT and `point'." "Show inline latex fragments between LIMIT and `point'."