Use jupyter-generate-request in jupyter-request

This commit is contained in:
Nathaniel Nicandro 2020-09-10 12:42:41 -05:00
parent 057c064fee
commit a23f8fe864
3 changed files with 20 additions and 18 deletions

View file

@ -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'.

View file

@ -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))

View file

@ -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)