mirror of
https://github.com/vale981/emacs-jupyter
synced 2025-03-05 15:41:37 -05:00
Add jupyter-org--first-result-context-p
Makes the code read better.
This commit is contained in:
parent
44e3823a93
commit
6005177537
1 changed files with 24 additions and 23 deletions
|
@ -1058,6 +1058,9 @@ new \"scalar\" result with the result of calling
|
||||||
|
|
||||||
;;;; Helper functions
|
;;;; Helper functions
|
||||||
|
|
||||||
|
(defsubst jupyter-org--first-result-context-p (context)
|
||||||
|
(eq (org-element-type context) 'keyword))
|
||||||
|
|
||||||
(defun jupyter-org--clear-request-id (req)
|
(defun jupyter-org--clear-request-id (req)
|
||||||
"Delete the ID of REQ in the `org-mode' buffer if present."
|
"Delete the ID of REQ in the `org-mode' buffer if present."
|
||||||
(unless (jupyter-org-request-id-cleared-p req)
|
(unless (jupyter-org-request-id-cleared-p req)
|
||||||
|
@ -1131,7 +1134,7 @@ appear after the element."
|
||||||
(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 drawer."
|
||||||
(cond
|
(cond
|
||||||
((eq (org-element-type context) 'keyword)
|
((jupyter-org--first-result-context-p context)
|
||||||
;; Only wrap the result if it can't be removed by `org-babel'.
|
;; Only wrap the result if it can't be removed by `org-babel'.
|
||||||
(if (jupyter-org-babel-result-p result) result
|
(if (jupyter-org-babel-result-p result) result
|
||||||
(jupyter-org-results-drawer result)))
|
(jupyter-org-results-drawer result)))
|
||||||
|
@ -1334,28 +1337,26 @@ results can be appended properly."
|
||||||
(jupyter-org-indent-inserted-region nil
|
(jupyter-org-indent-inserted-region nil
|
||||||
(jupyter-org--append-stream-result result)))
|
(jupyter-org--append-stream-result result)))
|
||||||
(t
|
(t
|
||||||
|
(unless (jupyter-org--first-result-context-p context)
|
||||||
(cl-case (org-element-type context)
|
(cl-case (org-element-type context)
|
||||||
;; Go to the end of the drawer to insert the new result.
|
;; Go to the end of the drawer to insert the new result.
|
||||||
(drawer
|
(drawer
|
||||||
(goto-char (jupyter-org-element-contents-end context)))
|
(goto-char (jupyter-org-element-contents-end context)))
|
||||||
;; Insert the first result. In this case `point' is at the first
|
;; Any other context that looks like a result needs to be removed
|
||||||
;; line after the #+RESULTS keyword.
|
;; since it, along with the new result will be wrapped in a drawer
|
||||||
(keyword nil)
|
;; and re-inserted into the buffer.
|
||||||
;; Any other context that looks like a result needs to be removed since
|
|
||||||
;; it, along with the new result will be wrapped in a drawer and
|
|
||||||
;; re-inserted into the buffer.
|
|
||||||
(table
|
(table
|
||||||
;; The `org-element-contents' of a table is nil which interferes with
|
;; The `org-element-contents' of a table is nil which interferes
|
||||||
;; how `org-element-table-interpreter' works when calling
|
;; with how `org-element-table-interpreter' works when calling
|
||||||
;; `org-element-interpret-data' so set the contents and delete CONTEXT
|
;; `org-element-interpret-data' so set the contents and delete
|
||||||
;; from the buffer.
|
;; CONTEXT from the buffer.
|
||||||
(org-element-set-contents
|
(org-element-set-contents
|
||||||
context (delete-and-extract-region
|
context (delete-and-extract-region
|
||||||
(org-element-property :contents-begin context)
|
(org-element-property :contents-begin context)
|
||||||
(jupyter-org-element-end-before-blanks context))))
|
(jupyter-org-element-end-before-blanks context))))
|
||||||
(t
|
(t
|
||||||
(when (jupyter-org--wrappable-element-p context)
|
(when (jupyter-org--wrappable-element-p context)
|
||||||
(jupyter-org--delete-element context))))
|
(jupyter-org--delete-element context)))))
|
||||||
(jupyter-org-indent-inserted-region
|
(jupyter-org-indent-inserted-region
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(forward-line -1)
|
(forward-line -1)
|
||||||
|
|
Loading…
Add table
Reference in a new issue