From dd01c4578cce2e3c25a3d06d30fb8b678a3bcd43 Mon Sep 17 00:00:00 2001 From: dickmao Date: Tue, 26 Feb 2019 17:58:42 -0500 Subject: [PATCH] reconnect kernel if necessary under org-ctrl-c-ctrl-c when `C-c C-c`, reconnect to kernel if it disconnected --- features/step-definitions/ein-steps.el | 7 ++++++- lisp/ein-kernel.el | 4 ++-- lisp/ein-shared-output.el | 5 ++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/features/step-definitions/ein-steps.el b/features/step-definitions/ein-steps.el index d471b72..fd65a1f 100644 --- a/features/step-definitions/ein-steps.el +++ b/features/step-definitions/ein-steps.el @@ -291,7 +291,12 @@ (When "^I wait for buffer to say \"\\(.+\\)\"$" (lambda (bogey) (ein:testing-wait-until - (lambda () (s-contains? bogey (buffer-string))) + (lambda () (ein:aif (s-contains? bogey (buffer-string)) it + (when (with-current-buffer ein:log-all-buffer-name + (search "WS closed unexpectedly" (buffer-string))) + (Then "I ctrl-c-ctrl-c") + (And "I clear log expr \"ein:log-all-buffer-name\"")) + nil)) nil 40000 2000))) (When "^I wait for cell to execute$" diff --git a/lisp/ein-kernel.el b/lisp/ein-kernel.el index b05a765..a46f31b 100644 --- a/lisp/ein-kernel.el +++ b/lisp/ein-kernel.el @@ -219,7 +219,7 @@ CALLBACK of arity 1, the kernel. (defun ein:kernel-reconnect-session (kernel &optional callback) "Check if session still exists. If it does, retrieve it. If it doesn't, ask the user to create a new session (ein:kernel-retrieve-session both retrieves and creates). -CALLBACK with arity 0 (e.g., execute cell now that we're reconnected)" +CALLBACK takes one argument kernel (e.g., execute cell now that we're reconnected)" (ein:kernel-disconnect kernel) (ein:kernel-session-p kernel @@ -320,7 +320,7 @@ delete the kernel on the server side" (ein:aand (ein:$kernel-websocket kernel) (ein:websocket-open-p it)))) (defun ein:kernel-when-ready (kernel callback) - "Execute CALLBACK of arity 0 (executing cell) when KERNEL is ready. Warn user otherwise." + "Execute CALLBACK of arity 1 (the kernel) when KERNEL is ready. Warn user otherwise." (if (ein:kernel-live-p kernel) (funcall callback kernel) (ein:log 'verbose "Kernel %s unavailable" (ein:$kernel-kernel-id kernel)) diff --git a/lisp/ein-shared-output.el b/lisp/ein-shared-output.el index c2df8a2..8bf93d8 100644 --- a/lisp/ein-shared-output.el +++ b/lisp/ein-shared-output.el @@ -214,7 +214,10 @@ shared output buffer. You can open the buffer by the command 'ein:shared-output-eval-string-history))) (unless kernel (setq kernel (ein:get-kernel-or-error))) (let ((cell (ein:shared-output-get-cell))) - (apply #'ein:cell-execute cell kernel (ein:trim-indent code) popup args))) + (ein:kernel-when-ready + kernel + (lambda (ready-kernel) + (apply #'ein:cell-execute cell ready-kernel (ein:trim-indent code) popup args))))) ;;; Generic getter