Change the spec of callbacks: msg-type is str now

Test ein:notebook-execute-current-cell is passed.
At this point all unit tests in test/test-ein-*.el are passed.

msg-type was first a string and I changed it to a keyword when I am
writing ein:kernel-execute.  But as I need to fix a lot of other
places, I change it back to a string.  Note that msg-type can come
from JSON directly when the notebook is first opened, so it must be
consistent with that routines.

Maybe I will change it again, but at that time, symbol is better than
keyword because msg-type is a value rather than a key.
This commit is contained in:
Takafumi Arakaki 2012-05-23 01:31:56 +02:00
parent 676e4ff523
commit 3985f97eb8
2 changed files with 14 additions and 15 deletions

View file

@ -754,16 +754,16 @@ Called from ewoc pretty printer via `ein:cell-insert-output'."
(defmethod ein:cell--handle-output ((cell ein:codecell) msg-type content) (defmethod ein:cell--handle-output ((cell ein:codecell) msg-type content)
(let* ((json (list :output_type msg-type))) (let* ((json (list :output_type msg-type)))
(case msg-type (ein:case-equal msg-type
(:stream (("stream")
(plist-put json :text (plist-get content :data)) (plist-put json :text (plist-get content :data))
(plist-put json :stream (plist-get content :name))) (plist-put json :stream (plist-get content :name)))
((:display_data :pyout) (("display_data" "pyout")
(when (eql msg-type :pyout) (when (equal msg-type "pyout")
(plist-put json :prompt_number (plist-get content :execution_count))) (plist-put json :prompt_number (plist-get content :execution_count)))
(setq json (ein:output-area-convert-mime-types (setq json (ein:output-area-convert-mime-types
json (plist-get content :data)))) json (plist-get content :data))))
(:pyerr (("pyerr")
(plist-put json :ename (plist-get content :ename)) (plist-put json :ename (plist-get content :ename))
(plist-put json :evalue (plist-get content :evalue)) (plist-put json :evalue (plist-get content :evalue))
(plist-put json :traceback (plist-get content :traceback)))) (plist-put json :traceback (plist-get content :traceback))))

View file

@ -302,8 +302,7 @@ For example, the EXECUTE-REPLY-CALLBACK is called as:
(`funcall' FUNCTION ARGUMENT CONTENT) (`funcall' FUNCTION ARGUMENT CONTENT)
.. [#output] One of `stream', `display_data', `pyout', `pyerr'. .. [#output] One of `stream', `display_data', `pyout', `pyerr'.
.. [#output2] The argument MSG-ID for the FUNCTION is `keyword'. .. [#output2] The argument MSG-ID for the FUNCTION is a string.
(e.g., `:stream')
.. [#clear]_ Content object has `stdout', `stderr' and `other' .. [#clear]_ Content object has `stdout', `stderr' and `other'
fields that are booleans. fields that are booleans.
@ -400,10 +399,10 @@ http://ipython.org/ipython-doc/dev/development/messaging.html#complete
(destructuring-bind (destructuring-bind
(&key header content parent_header &allow-other-keys) (&key header content parent_header &allow-other-keys)
(ein:json-read-from-string packet) (ein:json-read-from-string packet)
(let* ((msg-type (intern (format ":%s" (plist-get header :msg_type)))) (let* ((msg-type (plist-get header :msg_type))
(msg-id (plist-get parent_header :msg_id)) (msg-id (plist-get parent_header :msg_id))
(callbacks (ein:kernel-get-callbacks-for-msg kernel msg-id)) (callbacks (ein:kernel-get-callbacks-for-msg kernel msg-id))
(cb (plist-get callbacks msg-type))) (cb (plist-get callbacks (intern (format ":%s" msg-type)))))
(if cb (if cb
(ein:funcall-packed cb content) (ein:funcall-packed cb content)
(ein:log 'debug "no callback for: msg_type=%s msg_id=%s" (ein:log 'debug "no callback for: msg_type=%s msg_id=%s"
@ -429,18 +428,18 @@ http://ipython.org/ipython-doc/dev/development/messaging.html#complete
(destructuring-bind (destructuring-bind
(&key content parent_header header &allow-other-keys) (&key content parent_header header &allow-other-keys)
(ein:json-read-from-string packet) (ein:json-read-from-string packet)
(let* ((msg-type (intern (format ":%s" (plist-get header :msg_type)))) (let* ((msg-type (plist-get header :msg_type))
(callbacks (ein:kernel-get-callbacks-for-msg (callbacks (ein:kernel-get-callbacks-for-msg
kernel (plist-get parent_header :msg_id))) kernel (plist-get parent_header :msg_id)))
(events (ein:$kernel-events kernel))) (events (ein:$kernel-events kernel)))
(ein:log 'debug "HANDLE-IOPUB-REPLY: msg_type = %s" msg-type) (ein:log 'debug "HANDLE-IOPUB-REPLY: msg_type = %s" msg-type)
(if (and (not (eql msg-type :status)) (null callbacks)) (if (and (not (equal msg-type "status")) (null callbacks))
(ein:log 'verbose "Got message not from this kernel.") (ein:log 'verbose "Got message not from this kernel.")
(case msg-type (ein:case-equal msg-type
((:stream :display_data :pyout :pyerr) (("stream" "display_data" "pyout" "pyerr")
(ein:aif (plist-get callbacks :output) (ein:aif (plist-get callbacks :output)
(ein:funcall-packed it msg-type content))) (ein:funcall-packed it msg-type content)))
(:status (("status")
(ein:case-equal (plist-get content :execution_state) (ein:case-equal (plist-get content :execution_state)
(("busy") (("busy")
(ein:events-trigger events '(status_busy . Kernel))) (ein:events-trigger events '(status_busy . Kernel)))
@ -449,7 +448,7 @@ http://ipython.org/ipython-doc/dev/development/messaging.html#complete
(("dead") (("dead")
(ein:kernel-stop-channels kernel) (ein:kernel-stop-channels kernel)
(ein:events-trigger events '(status_dead . Kernel))))) (ein:events-trigger events '(status_dead . Kernel)))))
(:clear_output (("clear_output")
(ein:aif (plist-get callbacks :clear_output) (ein:aif (plist-get callbacks :clear_output)
(ein:funcall-packed it content)))))))) (ein:funcall-packed it content))))))))