Refactor ein:notification-setup

This commit is contained in:
Takafumi Arakaki 2012-10-09 23:35:36 +02:00
parent 1dee471f37
commit cc0f96e6e9
2 changed files with 24 additions and 20 deletions

View file

@ -504,21 +504,30 @@ This is equivalent to do ``C-c`` in the console program."
(with-current-buffer (ein:worksheet-buffer ws) (with-current-buffer (ein:worksheet-buffer ws)
(ein:notebook-mode) (ein:notebook-mode)
;; Now that major-mode is set, set buffer local variables: ;; Now that major-mode is set, set buffer local variables:
(ein:notification-setup (ein:notebook--notification-setup notebook)
(current-buffer)
(ein:$notebook-events notebook)
(lambda () (ein:$notebook-worksheets ein:%notebook%))
(lambda () ein:%worksheet%)
#'ein:worksheet-name
(lambda (ws)
(ein:notebook-worksheet--render-maybe ein:%notebook% ws "clicked")
(ein:worksheet-buffer ws))
(lambda (ws)
(ein:notebook-worksheet-delete ein:%notebook% ws t)))
(ein:notebook-setup-kill-buffer-hook) (ein:notebook-setup-kill-buffer-hook)
(ein:notebook-set-buffer-file-name-maybe notebook) (ein:notebook-set-buffer-file-name-maybe notebook)
(setq ein:%notebook% notebook))) (setq ein:%notebook% notebook)))
(defun ein:notebook--notification-setup (notebook)
(ein:notification-setup
(current-buffer)
(ein:$notebook-events notebook)
:get-list
(lambda () (ein:$notebook-worksheets ein:%notebook%))
:get-current
(lambda () ein:%worksheet%)
:get-name
#'ein:worksheet-name
:get-buffer
(lambda (ws)
(ein:notebook-worksheet--render-maybe ein:%notebook% ws "clicked")
(ein:worksheet-buffer ws))
:delete
(lambda (ws)
(ein:notebook-worksheet-delete ein:%notebook% ws t))
))
(defun ein:notebook-set-buffer-file-name-maybe (notebook) (defun ein:notebook-set-buffer-file-name-maybe (notebook)
"Set `buffer-file-name' of the current buffer to ipynb file "Set `buffer-file-name' of the current buffer to ipynb file
of NOTEBOOK." of NOTEBOOK."

View file

@ -152,8 +152,7 @@ where NS is `:kernel' or `:notebook' slot of NOTIFICATION."
(force-mode-line-update)))) (force-mode-line-update))))
packed))) packed)))
(defun ein:notification-setup (buffer events get-list get-current get-name (defun ein:notification-setup (buffer events &rest tab-slots)
get-buffer delete)
"Setup a new notification widget in the BUFFER. "Setup a new notification widget in the BUFFER.
This function saves the new notification widget instance in the This function saves the new notification widget instance in the
local variable of the BUFFER. local variable of the BUFFER.
@ -174,19 +173,15 @@ GET-BUFFER : function
DELETE : function DELETE : function
Remove a given worksheet. Remove a given worksheet.
"
\(fn buffer events &key get-list get-current get-name get-buffer delete)"
(with-current-buffer buffer (with-current-buffer buffer
(setq ein:%notification% (setq ein:%notification%
(ein:notification "NotificationWidget" :buffer buffer)) (ein:notification "NotificationWidget" :buffer buffer))
(setq header-line-format ein:header-line-format) (setq header-line-format ein:header-line-format)
(ein:notification-bind-events ein:%notification% events) (ein:notification-bind-events ein:%notification% events)
(oset ein:%notification% :tab (oset ein:%notification% :tab
(make-instance 'ein:notification-tab (apply #'make-instance 'ein:notification-tab tab-slots))
:get-list get-list
:get-current get-current
:get-name get-name
:get-buffer get-buffer
:delete delete))
ein:%notification%)) ein:%notification%))