If you see something, say something

Avoid silently failing as in #530 where kernelspec language is unrecognized.
This commit is contained in:
dickmao 2019-05-16 09:47:24 -04:00
parent f98d49ff94
commit 8738fa5e0a
3 changed files with 48 additions and 33 deletions

View file

@ -162,7 +162,10 @@ This function may raise an error."
(set-keymap-parent ein:notebook-multilang-mode-map ess-r-mode-map))))
(defun ein:ml-lang-setup (kernelspec)
(funcall (intern (concat "ein:ml-lang-setup-" (ein:$kernelspec-language kernelspec)))))
(let ((setup-func (intern (concat "ein:ml-lang-setup-" (ein:$kernelspec-language kernelspec)))))
(if (fboundp setup-func)
(funcall setup-func)
(error "ein:ml-lang-setup: kernelspec language '%s' unsupported" (ein:$kernelspec-language kernelspec)))))
;; (defun ein:ml-lang-setup-markdown ()
;; "Use `markdown-mode-map'. NOTE: This function is not used now."

View file

@ -403,22 +403,25 @@ where `created' indicates a new notebook or an existing one.
(ein:notebook-maybe-set-kernelspec notebook (plist-get (ein:$content-raw-content content) :metadata))
(ein:notebook-install-kernel notebook)
(ein:notebook-from-json notebook (ein:$content-raw-content content))
;; Start websocket only after worksheet is rendered
;; because ein:notification-bind-events only gets called after worksheet's
;; buffer local notification widget is instantiated
(ein:kernel-retrieve-session (ein:$notebook-kernel notebook))
(setf (ein:$notebook-kernelinfo notebook)
(ein:kernelinfo-new (ein:$notebook-kernel notebook)
(cons #'ein:notebook-buffer-list notebook)
(symbol-name (ein:get-mode-for-kernel (ein:$notebook-kernelspec notebook)))))
(ein:notebook-put-opened-notebook notebook)
(ein:notebook--check-nbformat (ein:$content-raw-content content))
(setf (ein:$notebook-q-checkpoints notebook) q-checkpoints)
(ein:notebook-enable-autosaves notebook)
(ein:gc-complete-operation)
(ein:log 'info "Notebook %s is ready" (ein:$notebook-notebook-name notebook)))
(when callback0
(funcall callback0)))
(if (not (with-current-buffer (ein:notebook-buffer notebook)
(ein:get-notebook)))
(error "ein:notebook-open--callback: notebook instantiation failed")
;; Start websocket only after worksheet is rendered
;; because ein:notification-bind-events only gets called after worksheet's
;; buffer local notification widget is instantiated
(ein:kernel-retrieve-session (ein:$notebook-kernel notebook))
(setf (ein:$notebook-kernelinfo notebook)
(ein:kernelinfo-new (ein:$notebook-kernel notebook)
(cons #'ein:notebook-buffer-list notebook)
(symbol-name (ein:get-mode-for-kernel (ein:$notebook-kernelspec notebook)))))
(ein:notebook-put-opened-notebook notebook)
(ein:notebook--check-nbformat (ein:$content-raw-content content))
(setf (ein:$notebook-q-checkpoints notebook) q-checkpoints)
(ein:notebook-enable-autosaves notebook)
(ein:gc-complete-operation)
(ein:log 'info "Notebook %s is ready" (ein:$notebook-notebook-name notebook))
(when callback0
(funcall callback0)))))
(defun ein:notebook-maybe-set-kernelspec (notebook content-metadata)
(ein:aif (plist-get content-metadata :kernelspec)
@ -666,22 +669,28 @@ This is equivalent to do ``C-c`` in the console program."
(defun ein:notebook--worksheet-render (notebook ws)
(ein:worksheet-render ws)
(with-current-buffer (ein:worksheet-buffer ws)
(if ein:polymode
(poly-ein-mode)
;; Changing major mode here is super dangerous as it
;; kill-all-local-variables.
;; Our saviour has been `ein:deflocal' which applies 'permanent-local
;; to variables assigned up to this point, but we ought not rely on it
(funcall (ein:notebook-choose-mode))
(ein:worksheet-reinstall-undo-hooks ws)
(ein:aif (ein:$notebook-kernelspec notebook)
(ein:ml-lang-setup it)))
(ein:notebook-mode)
(ein:notebook--notification-setup notebook)
(ein:notebook-setup-kill-buffer-hook)
(setq ein:%notebook% notebook)
(when ein:polymode
(poly-ein-fontify-buffer notebook))))
(let (multilang-failed)
(if ein:polymode
(poly-ein-mode)
;; Changing major mode here is super dangerous as it
;; kill-all-local-variables.
;; Our saviour has been `ein:deflocal' which applies 'permanent-local
;; to variables assigned up to this point, but we ought not rely on it
(funcall (ein:notebook-choose-mode))
(ein:worksheet-reinstall-undo-hooks ws)
(condition-case err
(ein:aif (ein:$notebook-kernelspec notebook)
(ein:ml-lang-setup it)
(error "ein:notebook--worksheet-render: No kernelspec found"))
(error (ein:log 'error (error-message-string err))
(setq multilang-failed t))))
(unless multilang-failed
(ein:notebook-mode)
(ein:notebook--notification-setup notebook)
(ein:notebook-setup-kill-buffer-hook)
(setq ein:%notebook% notebook)
(when ein:polymode
(poly-ein-fontify-buffer notebook))))))
(defun ein:notebook--notification-setup (notebook)
(ein:notification-setup

View file

@ -50,6 +50,9 @@ TYPE can be 'body, nil."
((ein:markdowncell-p cell) "markdown")
(t "fundamental"))))
((not (equal mode (ein:oref-safe cm :mode)))))
(when (eq mode 'poly-fallback-mode)
(ein:display-warning
(format "pm:get-span: no major mode for kernelspec language '%s'" lang)))
(setq result-cm
(loop for ocm in (eieio-oref pm/polymode '-auto-innermodes)
when (equal mode (ein:oref-safe ocm :mode))