From a23f8fe8649683a9a048d23eeafc19cd379c4ae7 Mon Sep 17 00:00:00 2001 From: Nathaniel Nicandro Date: Thu, 10 Sep 2020 12:42:41 -0500 Subject: [PATCH] Use `jupyter-generate-request` in `jupyter-request` --- jupyter-client.el | 4 ++-- jupyter-monads.el | 7 +++---- jupyter-org-client.el | 27 +++++++++++++++------------ 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/jupyter-client.el b/jupyter-client.el index 9f79abf..9eae1fe 100644 --- a/jupyter-client.el +++ b/jupyter-client.el @@ -359,7 +359,7 @@ this is called." ;;; Sending messages -(cl-defgeneric jupyter-generate-request ((_client jupyter-kernel-client) _msg) +(cl-defgeneric jupyter-generate-request (_client &rest slots) "Generate a `jupyter-request' object for MSG. This method gives an opportunity for subclasses to initialize a `jupyter-request' based on the current context. @@ -368,7 +368,7 @@ The default implementation returns a new `jupyter-request' with the default value for all slots. Note, the `:id' and `:inhibited-handlers' slots are overwritten by the caller of this method." - (jupyter-request)) + (apply #'make-jupyter-request slots)) (defun jupyter-verify-inhibited-handlers () "Verify the value of `jupyter-inhibit-handlers'. diff --git a/jupyter-monads.el b/jupyter-monads.el index bc0659d..aa26e43 100644 --- a/jupyter-monads.el +++ b/jupyter-monads.el @@ -473,9 +473,7 @@ Ex. Subscribe to a publisher and unsubscribe after receiving two (cl-defun jupyter-request (type &rest content) "Return an IO action that sends a `jupyter-request'. TYPE is the message type of the message that CONTENT, a property -list, represents. - -See `jupyter-io' for more information on IO actions." +list, represents." (declare (indent 1)) ;; TODO: Get rid of having to do this conversion. (unless (symbolp type) @@ -487,7 +485,8 @@ See `jupyter-io' for more information on IO actions." :stdin :shell)) (req-complete-pub (jupyter-publisher)) - (req (make-jupyter-request + (req (jupyter-generate-request + jupyter-current-client :type type :content content)) (id (jupyter-request-id req)) diff --git a/jupyter-org-client.el b/jupyter-org-client.el index c20290f..1144a7e 100644 --- a/jupyter-org-client.el +++ b/jupyter-org-client.el @@ -116,7 +116,7 @@ See also the docstring of `org-image-actual-width' for more details." (defvar org-babel-jupyter-current-src-block-params) -(cl-defmethod jupyter-generate-request ((_client jupyter-org-client) _msg) +(cl-defmethod jupyter-generate-request ((_client jupyter-org-client) &rest slots) "Return a `jupyter-org-request' for the current source code block." (if (and org-babel-current-src-block-location org-babel-jupyter-current-src-block-params @@ -133,17 +133,20 @@ See also the docstring of `org-image-actual-width' for more details." (let* ((context (org-element-context)) (block-params org-babel-jupyter-current-src-block-params) (result-params (alist-get :result-params block-params))) - (jupyter-org-request - :marker (copy-marker org-babel-current-src-block-location) - :inline-block-p (and (memq (org-element-type context) - '(inline-babel-call inline-src-block)) - t) - :result-type (alist-get :result-type block-params) - :file (alist-get :file block-params) - :block-params block-params - :async-p (equal (alist-get :async block-params) "yes") - :silent-p (car (or (member "none" result-params) - (member "silent" result-params)))))) + (apply #'jupyter-org-request + (append + (list + :marker (copy-marker org-babel-current-src-block-location) + :inline-block-p (and (memq (org-element-type context) + '(inline-babel-call inline-src-block)) + t) + :result-type (alist-get :result-type block-params) + :file (alist-get :file block-params) + :block-params block-params + :async-p (equal (alist-get :async block-params) "yes") + :silent-p (car (or (member "none" result-params) + (member "silent" result-params)))) + slots)))) (cl-call-next-method))) (cl-defmethod jupyter-drop-request ((_client jupyter-org-client)