Make kernelinfo language agnostic.

Or at least don't try to call Python code when the kernel language is not
Python.
This commit is contained in:
John Miller 2018-02-14 18:25:23 -06:00
parent 045d9e9a89
commit 2fec7cb20e
2 changed files with 15 additions and 7 deletions

View file

@ -41,17 +41,23 @@ in these buffer will be synced with the kernel's cwd.")
(hostname
:initarg :hostname :type string
:documentation "Host name of the machine where the kernel is running on.")
(language
:initarg :language :type string
:accessor ein:kernelinfo-language
:documentation "Language for the running kernel.")
(ccwd
:initarg :ccwd :type string
:documentation "cached CWD (last time checked CWD)."))
:documentation "Info related (but unimportant) to kernel")
(defun ein:kernelinfo-new (kernel get-buffers)
(defun ein:kernelinfo-new (kernel get-buffers kernel-language)
"Make a new `ein:kernelinfo' instance based on KERNEL and GET-BUFFERS."
(let ((kerinfo (make-instance 'ein:kernelinfo)))
(oset kerinfo :kernel kernel)
(oset kerinfo :get-buffers get-buffers)
(ein:kernelinfo-setup-hooks kerinfo)
(setf (slot-value kerinfo 'kernel) kernel)
(setf (slot-value kerinfo 'get-buffers) get-buffers)
(setf (slot-value kerinfo 'language) kernel-language)
(ein:case-equal kernel-language
("python" (ein:kernelinfo-setup-hooks kerinfo)))
kerinfo))
(defun ein:kernelinfo-setup-hooks (kerinfo)
@ -67,8 +73,9 @@ in these buffer will be synced with the kernel's cwd.")
(ein:log 'debug "EIN:KERNELINFO-UPDATE-ALL")
(ein:log 'debug "(ein:kernel-live-p kernel) = %S"
(ein:kernel-live-p (slot-value kerinfo 'kernel)))
(ein:kernelinfo-update-ccwd kerinfo)
(ein:kernelinfo-update-hostname kerinfo))
(when (string-equal (ein:kernelinfo-language kerinfo) "python")
(ein:kernelinfo-update-ccwd kerinfo)
(ein:kernelinfo-update-hostname kerinfo)))
(defun ein:kernelinfo-update-ccwd (kerinfo)
"Update cached current working directory (CCWD) and change

View file

@ -375,7 +375,8 @@ See `ein:notebook-open' for more information."
(ein:notebook-from-json notebook (ein:$content-raw-content content)) ; notebook buffer is created here
(setf (ein:$notebook-kernelinfo notebook)
(ein:kernelinfo-new (ein:$notebook-kernel notebook)
(cons #'ein:notebook-buffer-list notebook)))
(cons #'ein:notebook-buffer-list notebook)
(ein:get-kernelspec-language (ein:$notebook-kernelspec notebook))))
(ein:notebook-put-opened-notebook notebook)
(ein:notebook--check-nbformat (ein:$content-raw-content content))
(ein:notebook-enable-autosaves notebook)