diff --git a/jupyter-org-client.el b/jupyter-org-client.el index bf2d41c..2c231f8 100644 --- a/jupyter-org-client.el +++ b/jupyter-org-client.el @@ -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) diff --git a/ob-jupyter.el b/ob-jupyter.el index c00c18d..5b19aa8 100644 --- a/ob-jupyter.el +++ b/ob-jupyter.el @@ -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))))