@@ -65,16 +65,13 @@ See `org-babel-jupyter-file-name'."
65
65
66
66
(defun org-babel-variable-assignments:jupyter (params &optional lang )
67
67
" Assign variables in PARAMS according to the Jupyter kernel language.
68
- Use `org-babel-jupyter-src-block-lang' to get the kernel language
69
- of the src-block ELEMENT and call the variable assignment
70
- function for the language. ELEMENT defaults to the
71
- `org-element-at-point' . So if LANG is the kernel language, then
72
- call
68
+ LANG is the kernel language of the source block. If LANG is nil,
69
+ get the kernel language from the current source block.
73
70
74
- org-babel-variable-assignments:LANG
75
-
76
- If the above function doesn't exist or if no kernel langauge can
77
- be found, fall back to `org-babel-variable-assignments:python' ."
71
+ The variables are assigned by looking for the function
72
+ `org-babel-variable-assignments:LANG' . If this function does not
73
+ exist or if LANG cannot be determined, assign variables using
74
+ `org-babel-variable-assignments:python' ."
78
75
(let* ((lang (or lang
79
76
(save-excursion
80
77
(when (re-search-backward
@@ -91,18 +88,16 @@ be found, fall back to `org-babel-variable-assignments:python'."
91
88
BODY is the code to expand, PARAMS should be the header arguments
92
89
of the src block with BODY as its code, and VAR-LINES should be
93
90
the list of strings containing the variables to evaluate before
94
- executing body.
91
+ executing body. LANG is the kernel language of the source block.
95
92
96
93
This function is similar to
97
- `org-babel-variable-assignments:jupyter' in that it finds the
98
- kernel language of the src-block ELEMENT, defaulting to the
99
- `org-element-at-point' , to find get the kernel language of BODY.
100
- So if LANG is the kernel language, call the function
101
-
102
- org-babel-expand-body:LANG
94
+ `org-babel-variable-assignments:jupyter' in that it attempts to
95
+ find the kernel language of the source block if LANG is not
96
+ provided.
103
97
104
- to expand BODY. If the above function doesn't exist or if no
105
- kernel langauge can be found fall back to
98
+ BODY is expanded by calling the function
99
+ `org-babel-expand-body:LANG' . If this function doesn't exist or
100
+ if LANG cannot be determined, fall back to
106
101
`org-babel-expand-body:generic' ."
107
102
(let* ((lang (or lang
108
103
(save-excursion
@@ -132,7 +127,8 @@ the header variables in PARAMS."
132
127
(when var-lines
133
128
(jupyter-repl-replace-cell-code
134
129
(mapconcat #'identity var-lines " \n " ))
135
- ; ; For `org-babel-load-session:jupyter'
130
+ ; ; For `org-babel-load-session:jupyter' , ensure that the loaded code
131
+ ; ; starts on a new line.
136
132
(when no-execute
137
133
(insert " \n " )))
138
134
(unless no-execute
@@ -353,7 +349,7 @@ removal."
353
349
For example, call `org-babel-python-table-or-string' on the
354
350
results when rendering scalar data for a python code block.
355
351
356
- RENDER-RESULT should be the cons cell returned by
352
+ RENDER-RESULT is the cons cell returned by
357
353
`org-babel-jupyter-prepare-result' and KERNEL-LANG is the kernel
358
354
language."
359
355
(cl-destructuring-bind (render-param . result) render-result
@@ -364,23 +360,26 @@ language."
364
360
365
361
(defun org-babel-jupyter-insert-results (results params kernel-lang )
366
362
" Insert RESULTS at the current source block location.
367
- RESULTS is either a a single pair or a list of pairs with the form
363
+ RESULTS is either a single pair or a list of pairs, each pair
364
+ having the form
368
365
369
366
(RENDER-PARAM . RESULT)
370
367
371
368
i.e. the pairs returned by `org-babel-jupyter-prepare-result' .
372
- PARAMS should be the parameters passed to
373
- `org-babel-execute:jupyter' . KERNEL-LANG is the language of the
374
- kernel for the current source block. If optional argument APPEND
375
- is non-nil, then append RESULTS to the current results. The
376
- results will also be appended, regardless of the value of APPEND,
377
- if RESULTS is a list."
369
+ PARAMS are the parameters passed to `org-babel-execute:jupyter' .
370
+ KERNEL-LANG is the language of the kernel that produced RESULTS.
371
+
372
+ Note that for a list of results, the result which will appear
373
+ will be the last one in the list unless the source block has an
374
+ \" append\" or \" prepend\" parameter or some other way that
375
+ prevents `org-babel-insert-result' from clearing a result when
376
+ inserting a new one."
378
377
; ; Unless this is a list of results
379
378
(unless (car-safe (car results))
380
379
(setq results (list results)))
381
380
(cl-loop
382
- ; ; FIXME: This is a hack that relies on `org-babel-insert-result' only caring
383
- ; ; about the parameters of the info and not anything else.
381
+ ; ; FIXME: This is a hack that relies on `org-babel-insert-result' only
382
+ ; ; caring about the parameters of the info and not anything else.
384
383
with info = (list nil nil params)
385
384
with result-params = (alist-get :result-params params)
386
385
for (render-param . result) in
@@ -439,6 +438,7 @@ PARAMS."
439
438
(org-babel-jupyter--inject-render-param " append" params))
440
439
(org-babel-jupyter-insert-results result params kernel-lang))
441
440
(push result results)))))
441
+ ; ; TODO: Handle stream output and errors similar to ob-ipython
442
442
(jupyter-add-callback req
443
443
:stream
444
444
(lambda (msg )
@@ -494,10 +494,9 @@ PARAMS."
494
494
495
495
(defun org-babel-jupyter-make-language-alias (kernel lang )
496
496
" Simimilar to `org-babel-make-language-alias' but for Jupyter src-blocks.
497
- KERNEL should be the name of a the default kernel using for the
498
- kernel LANG. All necessary org-babel functions for a language
499
- with the name jupyter-LANG will be aliased to the jupyter
500
- functions."
497
+ KERNEL should be the name of the default kernel to use for kernel
498
+ LANG. All necessary org-babel functions for a language with the
499
+ name jupyter-LANG will be aliased to the jupyter functions."
501
500
(dolist (fn '(" execute" " expand-body" " prep-session" " edit-prep"
502
501
" variable-assignments" " load-session" ))
503
502
(let ((sym (intern-soft (concat " org-babel-" fn " :jupyter" ))))
@@ -523,8 +522,7 @@ Optional argument REFRESH has the same meaning as in
523
522
(cl-loop
524
523
for (kernel . (_dir . spec)) in (jupyter-available-kernelspecs refresh)
525
524
for lang = (plist-get spec :language )
526
- ; ; Only make aliases the first time a new language appears
527
- unless (functionp (intern (concat " org-babel-execute:jupyter-" lang)))
525
+ unless (member lang languages) collect lang into languages and
528
526
do (org-babel-jupyter-make-language-alias kernel lang)
529
527
; ; (add-to-list 'org-babel-tangle-lang-exts
530
528
; ; (cons (concat "jupyter-" lang) file_extension))
0 commit comments