mirror of
https://github.com/vale981/emacs-jupyter
synced 2025-03-05 07:41:37 -05:00
Add jupyter-org-request-at-point
* jupyter-org-client.el (jupyter-org-request-at-point): Do it. (org-babel-jupyter-src-block-session): New declare. * ob-jupyter.el (org-babel-jupyter-session-clients): Add doc about keys. * test/jupyter-test.el (jupyter-org-request-at-point): New test.
This commit is contained in:
parent
259e8c5b86
commit
1b1a55ef3f
3 changed files with 34 additions and 1 deletions
|
@ -34,6 +34,7 @@
|
|||
|
||||
(declare-function org-babel-python-table-or-string "ob-python" (results))
|
||||
(declare-function org-babel-jupyter-initiate-session "ob-jupyter" (&optional session params))
|
||||
(declare-function org-babel-jupyter-src-block-session "ob-jupyter" ())
|
||||
(declare-function org-babel-jupyter-language-p "ob-jupyter" (lang))
|
||||
(declare-function org-element-context "org-element" (&optional element))
|
||||
(declare-function org-element-type "org-element" (element))
|
||||
|
@ -153,6 +154,21 @@ See also the docstring of `org-image-actual-width' for more details."
|
|||
(when (markerp (jupyter-org-request-marker req))
|
||||
(set-marker (jupyter-org-request-marker req) nil)))
|
||||
|
||||
(defvar org-babel-jupyter-session-clients) ; in ob-jupyter.el
|
||||
|
||||
(defun jupyter-org-request-at-point ()
|
||||
"Return the `jupyter-org-request' associated with `point' or nil."
|
||||
(when-let* ((session (org-babel-jupyter-src-block-session))
|
||||
(client (gethash session org-babel-jupyter-session-clients)))
|
||||
(catch 'req
|
||||
(jupyter-map-pending-requests client
|
||||
(lambda (req)
|
||||
(when (jupyter-org-request-p req)
|
||||
(let ((marker (jupyter-org-request-marker req)))
|
||||
(and (equal (marker-position marker) (point))
|
||||
(equal (marker-buffer marker) (current-buffer))
|
||||
(throw 'req req)))))))))
|
||||
|
||||
;;;; Stream
|
||||
|
||||
(cl-defmethod jupyter-handle-stream ((_client jupyter-org-client)
|
||||
|
|
|
@ -53,7 +53,9 @@
|
|||
'jupyter-org-resource-directory)
|
||||
|
||||
(defvar org-babel-jupyter-session-clients (make-hash-table :test #'equal)
|
||||
"A hash table mapping session names to Jupyter clients.")
|
||||
"A hash table mapping session names to Jupyter clients.
|
||||
A key into this table can be constructed for the src-block at
|
||||
`point' using `org-babel-jupyter-src-block-session'.")
|
||||
|
||||
(defvar org-babel-header-args:jupyter '((kernel . :any)
|
||||
(async . ((yes no))))
|
||||
|
|
|
@ -1998,6 +1998,21 @@ Image(filename='%s', width=300)" file)
|
|||
(should (equal (jupyter-org-result req (list :text/plain "[1, 2, 3] Foo"))
|
||||
'(fixed-width (:value "[1, 2, 3] Foo"))))))
|
||||
|
||||
(ert-deftest jupyter-org-request-at-point ()
|
||||
:tags '(org)
|
||||
(jupyter-org-test
|
||||
(insert (format "\
|
||||
#+begin_src jupyter-python :session %s :async yes
|
||||
1 + 1;
|
||||
#+end_src" jupyter-org-test-session))
|
||||
(goto-char (point-min))
|
||||
(org-babel-execute-src-block)
|
||||
(let ((req (jupyter-org-request-at-point)))
|
||||
(should req)
|
||||
(should (jupyter-org-request-p req))
|
||||
(jupyter-wait-until-idle req)
|
||||
(should-not (jupyter-org-request-at-point)))))
|
||||
|
||||
(ert-deftest jupyter-org-result-python ()
|
||||
:tags '(org)
|
||||
;; Test that the python language specialized method calls
|
||||
|
|
Loading…
Add table
Reference in a new issue