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)
(ein:notebook-mode)
;; Now that major-mode is set, set buffer local variables:
(ein:notification-setup
(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--notification-setup notebook)
(ein:notebook-setup-kill-buffer-hook)
(ein:notebook-set-buffer-file-name-maybe 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)
"Set `buffer-file-name' of the current buffer to ipynb file
of NOTEBOOK."

View file

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