From 93199a392b17cda09bf22ca27b5bfc69d96c1759 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Mon, 4 Jun 2012 16:18:17 +0200 Subject: [PATCH] Remove cell from kernel-execute callbacks --- ein-cell.el | 7 ++++++- ein-kernel.el | 12 ++++++------ ein-notebook.el | 5 ++++- tests/test-ein-notebook.el | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/ein-cell.el b/ein-cell.el index acbeae1..af23702 100644 --- a/ein-cell.el +++ b/ein-cell.el @@ -93,6 +93,7 @@ (input :initarg :input :type string :documentation "Place to hold data until it is rendered via `ewoc'.") (outputs :initarg :outputs :initform nil :type list) + (events :initarg :events :type ein:events) (cell-id :initarg :cell-id :initform (ein:utils-uuid) :type string)) "Notebook cell base class") @@ -766,7 +767,7 @@ Called from ewoc pretty printer via `ein:cell-insert-output'." (list :execute_reply (cons #'ein:cell--handle-execute-reply cell) :output (cons #'ein:cell--handle-output cell) :clear_output (cons #'ein:cell--handle-clear-output cell) - :cell cell))) + :set_next_input (cons #'ein:cell--handle-set-next-input cell)))) (apply #'ein:kernel-execute kernel code callbacks args))) (defmethod ein:cell--handle-execute-reply ((cell ein:codecell) content) @@ -775,6 +776,10 @@ Called from ewoc pretty printer via `ein:cell-insert-output'." ;; (oset cell :dirty t) ) +(defmethod ein:cell--handle-set-next-input ((cell ein:codecell) text) + (ein:events-trigger + (oref cell :events) '(set_next_input . Cell) (list :cell cell :text text))) + ;;; Output area diff --git a/ein-kernel.el b/ein-kernel.el index 7f02353..49695f5 100644 --- a/ein-kernel.el +++ b/ein-kernel.el @@ -317,7 +317,7 @@ When calling this method pass a CALLBACKS structure of the form: (:execute_reply EXECUTE-REPLY-CALLBACK :output OUTPUT-CALLBACK :clear_output CLEAR-OUTPUT-CALLBACK - :cell CELL) + :set_next_input SET-NEXT-INPUT) Objects end with -CALLBACK above must pack a FUNCTION and its first ARGUMENT in a `cons': @@ -345,7 +345,7 @@ http://ipython.org/ipython-doc/dev/development/messaging.html#execute Output type messages is documented here: http://ipython.org/ipython-doc/dev/development/messaging.html#messages-on-the-pub-sub-socket -The CELL value may be use for the `set_next_input' payload. +The SET-NEXT-INPUT callback will be passed the `set_next_input' payload. See `ein:kernel--handle-shell-reply' for how the callbacks are called." (assert (ein:kernel-ready-p kernel)) @@ -443,9 +443,9 @@ http://ipython.org/ipython-doc/dev/development/messaging.html#complete (ein:log 'debug "no callback for: msg_type=%s msg_id=%s" msg-type msg-id)) (ein:aif (plist-get content :payload) - (ein:kernel--handle-payload kernel (plist-get callbacks :cell) it))))) + (ein:kernel--handle-payload kernel callbacks it))))) -(defun ein:kernel--handle-payload (kernel cell payload) +(defun ein:kernel--handle-payload (kernel callbacks payload) (loop with events = (ein:$kernel-events kernel) for p in payload for text = (plist-get p :text) @@ -456,8 +456,8 @@ http://ipython.org/ipython-doc/dev/development/messaging.html#complete events '(open_with_text . Pager) (list :text text))) else if (equal source "IPython.zmq.zmqshell.ZMQInteractiveShell.set_next_input") - do (ein:events-trigger - events '(set_next_input . Cell) (list :cell cell :text text)))) + do (ein:aif (plist-get callbacks :set_next_input) + (ein:funcall-packed it text)))) (defun ein:kernel--handle-iopub-reply (kernel packet) (destructuring-bind diff --git a/ein-notebook.el b/ein-notebook.el index 14e7abc..be7bc07 100644 --- a/ein-notebook.el +++ b/ein-notebook.el @@ -304,7 +304,10 @@ the time of execution." ;; Note: TYPE can be a string. ;; FIXME: unify type of TYPE to symbol or string. (apply #'ein:cell-from-type - (format "%s" type) :ewoc (ein:$notebook-ewoc notebook) args)) + (format "%s" type) + :ewoc (ein:$notebook-ewoc notebook) + :events (ein:$notebook-events notebook) + args)) (defun ein:notebook-get-cells (notebook) (let* ((ewoc (ein:$notebook-ewoc notebook)) diff --git a/tests/test-ein-notebook.el b/tests/test-ein-notebook.el index 8553bd1..7806b44 100644 --- a/tests/test-ein-notebook.el +++ b/tests/test-ein-notebook.el @@ -335,7 +335,7 @@ some text (list :execute_reply (cons #'ein:cell--handle-execute-reply cell) :output (cons #'ein:cell--handle-output cell) :clear_output (cons #'ein:cell--handle-clear-output cell) - :cell cell))) + :set_next_input (cons #'ein:cell--handle-set-next-input cell)))) (should (ein:$kernel-p kernel)) (should (ein:codecell-p cell)) (should (ein:$kernel-p (oref cell :kernel)))