mirror of
https://github.com/vale981/emacs-jupyter
synced 2025-03-04 15:41:37 -05:00
Handle inline results similar to non-inline
fixes #204 * jupyter-org-client.el (jupyter-handle-execute-result): Call `jupyter-org-result` on DATA when a code block is being evaluated inline.
This commit is contained in:
parent
7ffc27ed2e
commit
226a14b232
2 changed files with 36 additions and 11 deletions
|
@ -284,7 +284,7 @@ to."
|
|||
|
||||
;;;; Execute result
|
||||
|
||||
(cl-defmethod jupyter-handle-execute-result ((_client jupyter-org-client)
|
||||
(cl-defmethod jupyter-handle-execute-result ((client jupyter-org-client)
|
||||
(req jupyter-org-request)
|
||||
_execution-count
|
||||
data
|
||||
|
@ -292,17 +292,22 @@ to."
|
|||
(unless (eq (jupyter-org-request-result-type req) 'output)
|
||||
(cond
|
||||
((jupyter-org-request-inline-block-p req)
|
||||
;; For inline results, only text/plain results are allowed
|
||||
;; For inline results, only text/plain results are allowed at the moment.
|
||||
;;
|
||||
;; TODO: Possibly file links are allowed as well. See
|
||||
;; `org-babel-insert-result'
|
||||
(setq data (plist-get data :text/plain))
|
||||
(if (jupyter-org-request-async-p req)
|
||||
(org-with-point-at (jupyter-org-request-marker req)
|
||||
(org-babel-insert-result data))
|
||||
;; The results are returned in `org-babel-execute:jupyter' in the
|
||||
;; synchronous case
|
||||
(jupyter-org--add-result req data)))
|
||||
;; TODO: Handle all of the different macro types for inline results, see
|
||||
;; `org-babel-insert-result'.
|
||||
(setq data `(:text/plain ,(plist-get data :text/plain)))
|
||||
(let ((result (let ((r (jupyter-org-result req data metadata)))
|
||||
(if (stringp r) r
|
||||
(or (org-element-property :value r) "")))))
|
||||
(if (jupyter-org-request-async-p req)
|
||||
(org-with-point-at (jupyter-org-request-marker req)
|
||||
(org-babel-insert-result
|
||||
result (jupyter-org-request-block-params req)
|
||||
nil nil (jupyter-kernel-language client)))
|
||||
;; The results are returned in `org-babel-execute:jupyter' in the
|
||||
;; synchronous case
|
||||
(jupyter-org--add-result req result))))
|
||||
(t
|
||||
(jupyter-org--add-result req (jupyter-org-result req data metadata))))))
|
||||
|
||||
|
|
|
@ -2789,6 +2789,26 @@ publish_display_data({'text/plain': \"foo\", 'text/latex': \"$\\alpha$\"});"
|
|||
(forward-line)
|
||||
(should (looking-at-p ": 2\n"))))
|
||||
|
||||
(ert-deftest org-babel-jupyter-inline-blocks ()
|
||||
:tags '(org)
|
||||
(ert-info ("Treat inline and non-inline results similarly")
|
||||
;; #204
|
||||
(jupyter-org-test
|
||||
(insert (format "\
|
||||
#+NAME: hello_jupyter
|
||||
#+BEGIN_SRC jupyter-python :results value :display plain :session %s
|
||||
\"hello\"
|
||||
#+END_SRC
|
||||
|
||||
" jupyter-org-test-session))
|
||||
(insert "call_hello_jupyter()")
|
||||
(let ((pos (point)))
|
||||
(beginning-of-line)
|
||||
(org-ctrl-c-ctrl-c)
|
||||
(goto-char pos)
|
||||
(should (looking-at-p " {{{results(=hello=)}}}"))))))
|
||||
|
||||
|
||||
;; Local Variables:
|
||||
;; byte-compile-warnings: (unresolved obsolete lexical)
|
||||
;; eval: (and (functionp 'aggressive-indent-mode) (aggressive-indent-mode -1))
|
||||
|
|
Loading…
Add table
Reference in a new issue