Fix regression

In `org-babel-jupyter-initiate-session-by-key`, the function to
disassociate a client from a :session was added to the
`current-buffer`s value of `kill-buffer-hook` but it should be added
to the REPL buffer's value of that hook.

fixes #240

* ob-jupyter.el
(org-babel-jupyter-initiate-session-by-key): Add to the local value of
`kill-buffer-hook` in the REPL's buffer.

* test/jupyter-test.el
(org-babel-jupyter-initiate-session-by-key): New test.
This commit is contained in:
Nathaniel Nicandro 2020-04-14 10:58:48 -05:00
parent 587ed4e029
commit 97c421a698
3 changed files with 29 additions and 2 deletions

View file

@ -1,5 +1,10 @@
* master
- Fixed a regression that appears when executing an =org-mode= source
block of a previously created session. A new connection to the
session was being created before execution instead of using the old
connection. See #240.
- Fixed regression due to uppercase characters in kernel language
names, e.g. R. =emacs-jupyter= would not work at all with language
specific features.

View file

@ -371,8 +371,9 @@ the host."
(org-babel-jupyter-parse-session session)
kernel))
(puthash key client org-babel-jupyter-session-clients)
(let ((forget-client (lambda () (remhash key org-babel-jupyter-session-clients))))
(add-hook 'kill-buffer-hook forget-client nil t)))
(jupyter-with-repl-buffer client
(let ((forget-client (lambda () (remhash key org-babel-jupyter-session-clients))))
(add-hook 'kill-buffer-hook forget-client nil t))))
(oref client buffer)))
(defun org-babel-jupyter-initiate-session (&optional session params)

View file

@ -1900,6 +1900,27 @@ next(x"))))))
(should (org-babel-jupyter-session-p session))
(should (equal (org-babel-jupyter-session-name session) "foo/bar"))))
(ert-deftest org-babel-jupyter-initiate-session-by-key ()
:tags '(org)
(jupyter-org-test
(let ((session (make-temp-name "jupyter")))
(save-excursion
(insert
(format "#+begin_src jupyter-python :session %s\n1+1\n#+end_src\n"
session)))
(let* ((params (nth 2 (org-babel-get-src-block-info)))
(key (org-babel-jupyter-session-key params)))
(should-not (gethash key org-babel-jupyter-session-clients))
(let ((buffer (org-babel-jupyter-initiate-session-by-key
session params))
(client (gethash key org-babel-jupyter-session-clients)))
(should (bufferp buffer))
(should client)
(should (object-of-class-p client 'jupyter-repl-client))
(should (eq buffer (oref client buffer)))
(jupyter-test-kill-buffer buffer)
(should-not (gethash key org-babel-jupyter-session-clients)))))))
(ert-deftest ob-jupyter-no-results ()
:tags '(org)
(jupyter-org-test-src-block "1 + 1;" ""))