mirror of
https://github.com/vale981/emacs-ipython-notebook
synced 2025-03-05 17:11:41 -05:00
ein-jupyter: More stable ein:jupyter-server-start
Trying to increase reliability of starting a juptyer server from Emacs. Deferred is cool, but a pain to understand for this old brain. Fix some typos in ein-ob and be smarter selecting completion backend when connecting a python buffer to a jupyter notebook.
This commit is contained in:
parent
3fc8d55722
commit
1ab98b0c9d
3 changed files with 22 additions and 17 deletions
|
@ -393,7 +393,16 @@ notebook."
|
|||
:lighter (:eval (ein:connect-mode-get-lighter))
|
||||
:keymap ein:connect-mode-map
|
||||
:group 'ein
|
||||
(ein:complete-on-dot-install ein:connect-mode-map))
|
||||
(case ein:completion-backend
|
||||
(ein:use-ac-backend (ein:complete-on-dot-install ein:connect-mode-map)
|
||||
(auto-complete-mode +1))
|
||||
(ein:use-ac-jedi-backend (ein:jedi-complete-on-dot-install ein:connect-mode-map)
|
||||
(auto-complete-mode +1))
|
||||
(ein:use-company-backend (company-mode +1))
|
||||
(ein:use-company-jedi-backend (warn "Support for jedi+company currently not implemented. Defaulting to just company-mode")
|
||||
(company-mode +1))
|
||||
|
||||
(t (warn "No autocompletion backend has been selected - see `ein:completion-backend'."))))
|
||||
|
||||
(put 'ein:connect-mode 'permanent-local t)
|
||||
|
||||
|
|
|
@ -152,38 +152,34 @@ the log of the running jupyter server."
|
|||
(add-hook 'kill-emacs-hook #'(lambda ()
|
||||
(ein:jupyter-server-stop t)))
|
||||
(message "Starting notebook server in directory: %s" notebook-directory)
|
||||
(lexical-let ((no-login-after-start-p no-login-after-start-p))
|
||||
(lexical-let ((no-login-after-start-p no-login-after-start-p)
|
||||
(proc (ein:jupyter-server--run ein:jupyter-server-buffer-name
|
||||
*ein:last-jupyter-command*
|
||||
*ein:last-jupyter-directory*)))
|
||||
(deferred:$
|
||||
(deferred:timeout
|
||||
ein:jupyter-server-run-timeout 'ein:jupyter-timeout-sentinel
|
||||
(deferred:$
|
||||
(deferred:next
|
||||
(lambda ()
|
||||
(let ((proc (ein:jupyter-server--run ein:jupyter-server-buffer-name
|
||||
*ein:last-jupyter-command*
|
||||
*ein:last-jupyter-directory*)))
|
||||
proc)))
|
||||
(deferred:nextc it
|
||||
(lambda (proc)
|
||||
(deferred:lambda ()
|
||||
(with-current-buffer (process-buffer proc)
|
||||
(goto-char (point-min))
|
||||
(loop for x upfrom 0 by 1
|
||||
until (or (search-forward "Notebook is running at:" nil t)
|
||||
(search-forward "Use Control-C" nil t))
|
||||
do (progn (sit-for 0.1)
|
||||
(goto-char (point-min)))
|
||||
finally return no-login-after-start-p))))))
|
||||
(if (or (search-forward "Notebook is running at:" nil t)
|
||||
(search-forward "Use Control-C" nil t))
|
||||
no-login-after-start-p
|
||||
(deferred:nextc (deferred:wait (/ ein:jupyter-server-run-timeout 2)) self)))))))
|
||||
(deferred:nextc it
|
||||
(lambda (no-login-p)
|
||||
(if (eql no-login-p 'ein:jupyter-timeout-sentinel)
|
||||
(progn
|
||||
(error "[EIN] Jupyter server failed to start, cancelling operation.")
|
||||
(warn "[EIN] Jupyter server failed to start, cancelling operation.")
|
||||
(ein:jupyter-server-stop t))
|
||||
(ein:force-ipython-version-check)
|
||||
(unless no-login-p
|
||||
(ein:jupyter-server-login-and-open))))))))
|
||||
|
||||
;;;###autoload
|
||||
|
||||
(defun ein:jupyter-server-stop (&optional force)
|
||||
"Stop a running jupyter notebook server.
|
||||
|
||||
|
|
|
@ -143,7 +143,7 @@ jupyter kernels.
|
|||
|
||||
(defun org-babel-edit-prep:ein (babel-info)
|
||||
"Set up source code completion for editing and EIN source block."
|
||||
(let ((nb (ein:org-find-or-open-session gscdr (assoc :session (third babel-info))))))
|
||||
(let ((nb (ein:org-find-or-open-session (cdr (assoc :session (third babel-info))))))
|
||||
(ein:connect-buffer-to-notebook nb (current-buffer) t)))
|
||||
|
||||
;; This function should be used to assign any variables in params in
|
||||
|
|
Loading…
Add table
Reference in a new issue