Use pcase in jupyter--ioloop-filter

Also change the type of objects emitted by `jupyter--ioloop` to lists
This commit is contained in:
Nathaniel Nicandro 2018-01-06 21:04:03 -06:00
parent f42a22c586
commit 4896c6b75b

View file

@ -186,7 +186,8 @@ using the CHANNEL's socket."
(alist-get (car b) priorities))))))))) (alist-get (car b) priorities)))))))))
(cl-loop (cl-loop
while (not (ring-empty-p queue)) while (not (ring-empty-p queue))
do (zmq-prin1 (cons 'recvd (ring-remove queue))))) for (ctype . msg) = (ring-remove queue)
do (zmq-prin1 (list 'recvd ctype msg))))
(recv-message (recv-message
(sock ctype) (sock ctype)
(when (= (ring-length queue) (ring-size queue)) (when (= (ring-length queue) (ring-size queue))
@ -195,8 +196,7 @@ using the CHANNEL's socket."
(send-message (send-message
(sock ctype rest) (sock ctype rest)
(zmq-prin1 (zmq-prin1
(cons 'sent (list 'sent ctype (apply #'jupyter-send session sock rest))))
(cons ctype (apply #'jupyter-send session sock rest)))))
(start-channel (start-channel
(sock) (sock)
(zmq-connect (zmq-connect
@ -264,7 +264,7 @@ using the CHANNEL's socket."
(zmq-socket-set s zmq-LINGER 0) (zmq-socket-set s zmq-LINGER 0)
(zmq-close s)) (zmq-close s))
(mapcar #'car channels)))) (mapcar #'car channels))))
(quit (zmq-prin1 (cons 'quit (cons nil nil)))))))))) (quit (zmq-prin1 (list 'quit)))))))))
(defun jupyter--ioloop-pop-request (client) (defun jupyter--ioloop-pop-request (client)
(let* ((ring (process-get (oref client ioloop) :jupyter-pending-requests)) (let* ((ring (process-get (oref client ioloop) :jupyter-pending-requests))
@ -287,33 +287,36 @@ using the CHANNEL's socket."
(oset client ioloop nil)))) (oset client ioloop nil))))
(defun jupyter--ioloop-filter (client event) (defun jupyter--ioloop-filter (client event)
(cl-destructuring-bind (ctype . data) (cdr event) "The process filter for CLIENT's ioloop subprocess.
(cl-case (car event) EVENT will be an s-expression emitted from the function returned
;; Cleanup handled in sentinel by `jupyter--ioloop'."
(quit) (pcase event
(sent (`(sent ,ctype ,msg-id)
(when jupyter--debug (when jupyter--debug
(message "SEND: %s" data)) (message "SEND: %s" msg-id))
(unless (eq ctype :stdin) (unless (eq ctype :stdin)
;; Anything sent on stdin is a reply and therefore never added to ;; Anything sent on stdin is a reply and therefore never added to
;; `:jupyter-pending-requests' ;; `:jupyter-pending-requests'
(let ((id data) (let ((req (jupyter--ioloop-pop-request client)))
(req (jupyter--ioloop-pop-request client))) (setf (jupyter-request--id req) msg-id)
(setf (jupyter-request--id req) id) (puthash msg-id req (oref client requests)))))
(puthash id req (oref client requests))))) (`(recvd ,ctype ,msg)
(recvd
(when jupyter--debug (when jupyter--debug
(message "RECV: %s %s %s" (message "RECV: %s %s %s"
(jupyter-message-type (cdr data)) (jupyter-message-type (cdr msg))
(jupyter-message-parent-id (cdr data)) (jupyter-message-parent-id (cdr msg))
(jupyter-message-content (cdr data)))) (jupyter-message-content (cdr msg))))
(let ((channel (cl-find-if (lambda (c) (eq (oref c type) ctype)) (let ((channel (cl-find-if (lambda (c) (eq (oref c type) ctype))
(mapcar (lambda (x) (slot-value client x)) (mapcar (lambda (x) (slot-value client x))
'(stdin-channel '(stdin-channel
shell-channel shell-channel
iopub-channel))))) iopub-channel)))))
(jupyter-push-message channel data) (jupyter-push-message channel msg)
(run-with-timer 0.001 nil #'jupyter-handle-message client channel)))))) (run-with-timer 0.001 nil #'jupyter-handle-message client channel)))
('(quit)
;; Cleanup handled in sentinel
(when jupyter--debug
(message "KERNEL KILLED")))))
(cl-defmethod jupyter-start-channels ((client jupyter-kernel-client) (cl-defmethod jupyter-start-channels ((client jupyter-kernel-client)
&key (shell t) &key (shell t)