From 6b7ecfcf0891bafa21e0329bb861a9cbfec801c3 Mon Sep 17 00:00:00 2001 From: Nathaniel Nicandro Date: Sun, 13 Jan 2019 13:44:32 -0600 Subject: [PATCH] Add execution-count slot to a `jupyter-kernel-client` This allows the default `jupyter-kernel-client' implementation to do the work of updating the execution count instead of having subclasses track it. --- jupyter-client.el | 13 +++++++++++++ jupyter-org-client.el | 6 ++---- jupyter-repl.el | 9 ++------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/jupyter-client.el b/jupyter-client.el index 48433cf..9ca0f42 100644 --- a/jupyter-client.el +++ b/jupyter-client.el @@ -95,6 +95,12 @@ client's ioloop slot.") :initform "idle" :documentation "The current state of the kernel. Can be either \"idle\", \"busy\", or \"starting\".") + (execution-count + :type integer + :initform 1 + :documentation "The *next* execution count of the kernel. +I.e., the execution count that will be assigned to the +next :execute-request sent to the kernel.") (requests :type hash-table :initform (make-hash-table :test 'equal) @@ -1907,6 +1913,13 @@ If RESTART is non-nil, request a restart instead of a complete shutdown." (declare (indent 1)) nil) +(cl-defmethod jupyter-handle-execute-input :before ((client jupyter-kernel-client) + _req + _code + execution-count) + "Set CLIENT's execution-count slot to 1 + EXECUTION-COUNT." + (oset client execution-count (1+ execution-count))) + (cl-defgeneric jupyter-handle-execute-result ((_client jupyter-kernel-client) _req _execution-count diff --git a/jupyter-org-client.el b/jupyter-org-client.el index 796f66d..1521093 100644 --- a/jupyter-org-client.el +++ b/jupyter-org-client.el @@ -276,14 +276,12 @@ to." (forward-line) (insert (org-element-normalize-string (plist-get pl :text)))))) -(cl-defmethod jupyter-handle-execute-reply ((client jupyter-org-client) +(cl-defmethod jupyter-handle-execute-reply ((_client jupyter-org-client) (req jupyter-org-request) status - execution-count + _execution-count _user-expressions payload) - ;; TODO: Re-use the REPL's handler somehow? - (oset client execution-count (1+ execution-count)) (when payload (save-excursion (goto-char (jupyter-org-request-marker req)) diff --git a/jupyter-repl.el b/jupyter-repl.el index e95b50c..a6f2419 100644 --- a/jupyter-repl.el +++ b/jupyter-repl.el @@ -130,11 +130,7 @@ timeout, the built-in is-complete handler is used." :initform nil :documentation "Whether or not we should wait to clear the current output of the cell. Set when the kernel sends a -`:clear-output' message.") - (execution-count - :type integer - :initform 1 - :documentation "The current execution count of the kernel."))) +`:clear-output' message."))) (defvar-local jupyter-repl-lang-buffer nil "A buffer with the `major-mode' set to the REPL language's `major-mode'.") @@ -738,10 +734,9 @@ lines, truncate it to something less than (cl-defmethod jupyter-handle-execute-reply ((client jupyter-repl-client) _req _status - execution-count + _execution-count _user-expressions payload) - (oset client execution-count (1+ execution-count)) (jupyter-with-repl-buffer client (when payload (jupyter-handle-payload payload))))