@@ -234,6 +234,30 @@ Do this only if the file exists in
234
234
(file-exists-p link-path))
235
235
(delete-file link-path))))))))
236
236
237
+ ; ; TODO: A cleaner way to do this. Maybe just removing the file parameter from
238
+ ; ; the arguments all together and adding a new file slot in
239
+ ; ; `jupyter-org-request' . The real issue is that we have to deal with the fact
240
+ ; ; the `org-babel' assumes how the results of a code block are formatted is
241
+ ; ; controlled by the header arguments, but Jupyter controls the way that
242
+ ; ; results are displayed through the contents of the messages passed to Emacs
243
+ ; ; during the evaluation of a code block.
244
+ (defun org-babel-jupyter-temporarily-clear-file-param (params )
245
+ " Destructively remove the file result parameter from PARAMS.
246
+ Re-add the file parameters on the next call to
247
+ `org-babel-after-execute-hook' ."
248
+ (let* ((result-params (assq :result-params params))
249
+ (fresult (member " file" result-params))
250
+ (fparam (assq :file params)))
251
+ (setcar fresult " scalar" )
252
+ (delq fparam params)
253
+ (cl-labels
254
+ ((reset
255
+ ()
256
+ (setcar fresult " file" )
257
+ (when fparam (nconc params (list fparam)))
258
+ (remove-hook 'org-babel-after-execute-hook #'reset t )))
259
+ (add-hook 'org-babel-after-execute-hook #'reset nil t ))))
260
+
237
261
(defun org-babel-execute:jupyter (body params )
238
262
" Execute BODY according to PARAMS.
239
263
BODY is the code to execute for the current Jupyter `:session' in
@@ -254,6 +278,8 @@ the PARAMS alist."
254
278
:code code))))
255
279
(when (member " replace" (assq :result-params params))
256
280
(org-babel-jupyter-cleanup-file-links))
281
+ (when (member " file" (assq :result-params params))
282
+ (org-babel-jupyter-temporarily-clear-file-param params))
257
283
(cond
258
284
((or (equal (alist-get :async params) " yes" )
259
285
(plist-member params :async ))
0 commit comments