Add org-babel-jupyter-current-src-block-params

This is needed because `org-mode` merges many sources of source block params so
its not enough to just re-compute the parameters in `jupyter-generate-request`
using `org-babel-get-src-block-info` or `org-babel-log-get-info`.
This commit is contained in:
Nathaniel Nicandro 2019-09-01 11:43:46 -05:00
parent aa9b634e7b
commit 79ddd9357e
2 changed files with 16 additions and 4 deletions

View file

@ -114,18 +114,20 @@ See also the docstring of `org-image-actual-width' for more details."
;;;; `jupyter-request' interface
(defvar org-babel-jupyter-current-src-block-params)
(cl-defmethod jupyter-generate-request ((_client jupyter-org-client) _msg
&context (major-mode (eql org-mode)))
"Return a `jupyter-org-request' for the current source code block."
(if org-babel-current-src-block-location
(if (and org-babel-current-src-block-location
org-babel-jupyter-current-src-block-params)
;; Only use a `jupyter-org-request' when executing code blocks, setting
;; the `major-mode' context isn't enough, consider when a client is
;; started due to sending a completion request.
(save-excursion
(goto-char org-babel-current-src-block-location)
(let* ((context (org-element-context))
(block-params (nth 2 (or (org-babel-get-src-block-info nil context)
(org-babel-lob-get-info context))))
(block-params org-babel-jupyter-current-src-block-params)
(result-params (alist-get :result-params block-params)))
(jupyter-org-request
:marker (copy-marker org-babel-current-src-block-location)

View file

@ -378,11 +378,21 @@ These parameters are handled internally."
(setcar fresult "")
(delq fparam params)))
(defvar org-babel-jupyter-current-src-block-params nil
"The block params of the currently executed source block.
`org-mode' merges many different sources of source block
parameters that cannot be obtained by just calling
`org-babel-log-get-info' or `org-babel-get-src-block-info' so
this variable exists to ensure `jupyter-generate-request' uses
the parameters that `org-mode' provides when evaluating a source
block.")
(defun org-babel-execute:jupyter (body params)
"Execute BODY according to PARAMS.
BODY is the code to execute for the current Jupyter `:session' in
the PARAMS alist."
(let* ((jupyter-current-client
(let* ((org-babel-jupyter-current-src-block-params params)
(jupyter-current-client
(thread-first (alist-get :session params)
(org-babel-jupyter-initiate-session params)
(thread-last (buffer-local-value 'jupyter-current-client))))