diff --git a/lisp/ein-cell.el b/lisp/ein-cell.el index 98442b7..227a7c9 100644 --- a/lisp/ein-cell.el +++ b/lisp/ein-cell.el @@ -908,7 +908,7 @@ Called from ewoc pretty printer via `ein:cell-insert-output'." (ein:cell-set-input-prompt cell (plist-get content :execution_count)) (ein:cell-running-set cell nil) (let ((events (oref cell :events))) - (ein:events-trigger events 'set_dirty.Notebook '(:value t)) + (ein:events-trigger events 'set_dirty.Worksheet (list :value t :cell cell)) (ein:events-trigger events 'maybe_reset_undo.Notebook cell))) (defmethod ein:cell--handle-set-next-input ((cell ein:codecell) text) diff --git a/lisp/ein-notebook.el b/lisp/ein-notebook.el index 43f1b23..faeaa9e 100644 --- a/lisp/ein-notebook.el +++ b/lisp/ein-notebook.el @@ -384,15 +384,7 @@ of minor mode." (defun ein:notebook-bind-events (notebook events) "Bind events related to PAGER to the event handler EVENTS." (setf (ein:$notebook-events notebook) events) - ;; As IPython support only supports whole-notebook saving, there is - ;; no need for finer-level `set_dirty.Notebook'. Keep this until - ;; IPython supports finer-level saving. - (ein:events-on events - 'set_dirty.Notebook - (lambda (notebook data) - (setf (ein:$notebook-dirty notebook) - (plist-get data :value))) - notebook) + (ein:worksheet-class-bind-events events) ;; As calling multiple callbacks for this event does not make sense, ;; I amadding this in notebook instead of worksheet. (ein:events-on events diff --git a/lisp/ein-shared-output.el b/lisp/ein-shared-output.el index 5182324..5f8ee7b 100644 --- a/lisp/ein-shared-output.el +++ b/lisp/ein-shared-output.el @@ -115,7 +115,7 @@ (defun ein:shared-output-bind-events (events) "Add dummy event handlers." - (ein:events-on events 'set_dirty.Notebook #'ignore) + (ein:events-on events 'set_dirty.Worksheet #'ignore) (ein:events-on events 'maybe_reset_undo.Notebook #'ignore)) (defun ein:shared-output-get-cell () diff --git a/lisp/ein-worksheet.el b/lisp/ein-worksheet.el index 229a89a..81bf267 100644 --- a/lisp/ein-worksheet.el +++ b/lisp/ein-worksheet.el @@ -82,6 +82,10 @@ (mapc (lambda (cell) (oset cell :events events)) (ein:worksheet-get-cells ws)))) +(defun ein:worksheet-class-bind-events (events) + "Binds event handlers which are not needed to be bound per instance." + (ein:events-on events 'set_dirty.Worksheet #'ein:worksheet--set-dirty)) + (defmethod ein:worksheet--set-next-input ((ws ein:worksheet) data) (destructuring-bind (&key cell text) data (if (eq (oref cell :ewoc) (oref ws :ewoc)) ; CELL is in this WS @@ -91,6 +95,12 @@ (ein:log 'debug "WORKSHEET--SET-NEXT-INPUT: CELL is not in this buffer.")))) +(defun ein:worksheet--set-dirty (-ignore- data) + "Set dirty flag of worksheet in which CELL in DATA locates." + (destructuring-bind (&key value cell) data + (ein:with-live-buffer (ein:cell-buffer cell) + (oset ein:%worksheet% :dirty value)))) + (defmethod ein:worksheet-notebook-name ((ws ein:worksheet)) (ein:notebook-name (oref ws :notebook)))