diff --git a/jupyter-base.el b/jupyter-base.el index 903d0c6..cf05d3c 100644 --- a/jupyter-base.el +++ b/jupyter-base.el @@ -117,7 +117,11 @@ from the kernel.") "MIME types that can be used in terminal Emacs.") (defvar jupyter--debug nil - "When non-nil, some parts of Jupyter will emit debug statements.") + "When non-nil, some parts of Jupyter will emit debug statements. +If the symbol 'message, messages received by a kernel will only +be handled by clients when the function +`jupyter--debug-run-message-queue' is called manually. This +allows for stepping through the code with Edebug.") (defvar jupyter-default-timeout 2.5 diff --git a/jupyter-client.el b/jupyter-client.el index 20a693e..a5cd93c 100644 --- a/jupyter-client.el +++ b/jupyter-client.el @@ -586,12 +586,25 @@ back." (when jupyter--debug (jupyter--show-event event))) +(defvar jupyter--debug-message-queue nil) + (cl-defmethod jupyter-event-handler ((client jupyter-kernel-client) (event (head message))) (when jupyter--debug (jupyter--show-event event)) - (cl-destructuring-bind (_ channel _idents . msg) event - (jupyter-handle-message client channel msg))) + (if (eq jupyter--debug 'message) + (push + (cl-destructuring-bind (_ channel _idents . msg) event + (lambda () + (jupyter-handle-message client channel msg))) + jupyter--debug-message-queue) + (cl-destructuring-bind (_ channel _idents . msg) event + (jupyter-handle-message client channel msg)))) + +(defun jupyter--debug-run-message-queue () + (let ((queue (reverse jupyter--debug-message-queue))) + (setq jupyter--debug-message-queue nil) + (cl-loop for thunk in queue do (funcall thunk)))) ;;; Starting communication with a kernel