mirror of
https://github.com/vale981/emacs-ipython-notebook
synced 2025-03-05 17:11:41 -05:00
Start using notification widget
This commit is contained in:
parent
e87ddd2bb2
commit
315b106c96
3 changed files with 18 additions and 66 deletions
|
@ -31,67 +31,18 @@
|
|||
(require 'ein-log)
|
||||
(require 'ein-utils)
|
||||
|
||||
;; FIXME: header-line stuff must be moved to the notification widget module.
|
||||
(defvar ein:header-line-format '(:eval (ein:header-line)))
|
||||
|
||||
(defun ein:header-line ()
|
||||
(format
|
||||
"IP[y]: %s"
|
||||
(ein:join-str
|
||||
" | "
|
||||
(ein:filter
|
||||
'identity
|
||||
(list (ein:events-header-message-notebook)
|
||||
(ein:events-header-message-kernel))))))
|
||||
|
||||
(defun ein:header-line-setup-maybe ()
|
||||
"Setup `header-line-format' for mumamo.
|
||||
As `header-line-format' is buffer local variable, it must be set
|
||||
for each chunk when in
|
||||
See also `ein:ac-setup-maybe'."
|
||||
(and (ein:eval-if-bound 'ein:notebook)
|
||||
(ein:eval-if-bound 'mumamo-multi-major-mode)
|
||||
(setq header-line-format ein:header-line-format)))
|
||||
(add-hook 'after-change-major-mode-hook 'ein:header-line-setup-maybe)
|
||||
|
||||
|
||||
;;; Events handling class
|
||||
|
||||
;; FIXME: After moving header-line stuff to the notification widget,
|
||||
;; this buffer local variable will not be needed.
|
||||
(ein:deflocal ein:@events nil
|
||||
"Buffer local variable to hold an instance of `ein:events'.")
|
||||
|
||||
(defclass ein:events ()
|
||||
((buffer :initarg :buffer :type buffer :document "Notebook buffer")
|
||||
(callbacks :initarg :callbacks :type hash-table
|
||||
:initform (make-hash-table :test 'equal))
|
||||
(status-notebook :initarg :status-notebook :initform nil :type symbol)
|
||||
(status-kernel :initarg :status-kernel :initform nil :type symbol))
|
||||
:initform (make-hash-table :test 'equal)))
|
||||
"Event handler class.")
|
||||
|
||||
;; FIXME: This function must be moved to the notification widget.
|
||||
(defun ein:events-setup (buffer)
|
||||
"Make a new event handler instance and setup local variable in the BUFFER.
|
||||
The newly created instance is returned by this function. Event
|
||||
handler user must *not* use the buffer local variable directly.
|
||||
Use the variable returned by this function instead."
|
||||
(with-current-buffer buffer
|
||||
(setq ein:@events (ein:events "Events" :buffer buffer))
|
||||
(setq header-line-format ein:header-line-format)
|
||||
ein:@events))
|
||||
|
||||
(defun ein:events-header-message-notebook ()
|
||||
(case (oref ein:@events :status-notebook)
|
||||
(notebook_saving "Saving Notebook...")
|
||||
(notebook_saved "Notebook is saved")
|
||||
(notebook_save_failed "Failed to save Notebook!")))
|
||||
|
||||
(defun ein:events-header-message-kernel ()
|
||||
(case (oref ein:@events :status-kernel)
|
||||
(status_idle nil)
|
||||
(status_busy "Kernel is busy...")
|
||||
(status_dead "Kernel is dead. Need restart.")))
|
||||
(defun ein:events-new (buffer)
|
||||
"Return a new event handler instance."
|
||||
(ein:events "Events" :buffer buffer))
|
||||
|
||||
(defun ein:events-trigger (events event-type &optional data)
|
||||
"Trigger EVENT-TYPE and let event handler EVENTS handle that event.
|
||||
|
@ -103,15 +54,8 @@ IPython notebook client JS."
|
|||
;; This helps logging by `ein:log' (and maybe EWOC?).
|
||||
(with-current-buffer (oref events :buffer)
|
||||
(ein:aif (gethash event-type (oref events :callbacks))
|
||||
(mapc (lambda (cb-arg) (ein:funcall-packed cb-arg data)) it))
|
||||
;; FIXME! the following must be put together in the event frame work.
|
||||
(case (cdr event-type)
|
||||
(Kernel
|
||||
(oset events :status-kernel (car event-type)))
|
||||
(Notebook
|
||||
(oset events :status-notebook (car event-type)))
|
||||
(t
|
||||
(ein:log 'info "Unknown event: %S" event-type)))))
|
||||
(mapc (lambda (cb-arg) (ein:funcall-packed cb-arg data)) it)
|
||||
(ein:log 'info "Unknown event: %S" event-type))))
|
||||
|
||||
|
||||
(defmethod ein:events-on ((events ein:events) event-type
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
(require 'ein-completer)
|
||||
(require 'ein-pager)
|
||||
(require 'ein-events)
|
||||
(require 'ein-notification)
|
||||
(require 'ein-kill-ring)
|
||||
|
||||
(defvar ein:base-kernel-url "/")
|
||||
|
@ -88,7 +89,10 @@
|
|||
Notebook file format version.
|
||||
|
||||
`ein:$notebook-events' : `ein:$events'
|
||||
Event handler instance."
|
||||
Event handler instance.
|
||||
|
||||
`ein:$notebook-notification' : `ein:notification'
|
||||
Notification widget."
|
||||
url-or-port
|
||||
notebook-id
|
||||
data
|
||||
|
@ -100,6 +104,7 @@
|
|||
notebook-name
|
||||
nbformat
|
||||
events
|
||||
notification
|
||||
)
|
||||
|
||||
(ein:deflocal ein:notebook nil
|
||||
|
@ -204,8 +209,9 @@ the time of execution."
|
|||
(ein:notebook-from-json ein:notebook (ein:$notebook-data ein:notebook))
|
||||
(setq buffer-undo-list nil) ; clear undo history
|
||||
(ein:notebook-mode)
|
||||
(ein:notebook-bind-events ein:notebook
|
||||
(ein:events-setup (current-buffer)))
|
||||
(setf (ein:$notebook-notification ein:notebook)
|
||||
(ein:notification-setup (current-buffer)))
|
||||
(ein:notebook-bind-events ein:notebook (ein:events-new (current-buffer)))
|
||||
(ein:notebook-start-kernel)
|
||||
(ein:log 'info "Notebook %s is ready"
|
||||
(ein:$notebook-notebook-name ein:notebook)))
|
||||
|
@ -227,6 +233,8 @@ the time of execution."
|
|||
#'ein:notebook--set-next-input
|
||||
notebook)
|
||||
;; Bind events for sub components:
|
||||
(ein:notification-bind-events (ein:$notebook-notification ein:notebook)
|
||||
events)
|
||||
(setf (ein:$notebook-pager notebook)
|
||||
(ein:pager-new
|
||||
(format ein:notebook-pager-buffer-name-template
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
(with-current-buffer (ein:notebook-url-retrieve-callback
|
||||
nil
|
||||
(ein:notebook-new "DUMMY-URL" notebook-id))
|
||||
(let ((events (ein:events-setup (current-buffer))))
|
||||
(let ((events (ein:events-new (current-buffer))))
|
||||
(setf (ein:$notebook-events ein:notebook) events)
|
||||
(setf (ein:$notebook-kernel ein:notebook)
|
||||
(ein:kernel-new 8888 "/kernels" events)))
|
||||
|
|
Loading…
Add table
Reference in a new issue