Treat discarding case better in ein:notebook-ask-before-kill-buffer

Note that the test ein:notebook-to-json-after-closing-a-worksheet
fails now.
This commit is contained in:
Takafumi Arakaki 2012-08-30 02:32:53 +02:00
parent 2c8b8cce31
commit d25f6a1c02
2 changed files with 13 additions and 4 deletions

View file

@ -930,10 +930,15 @@ Note that print page is not supported in IPython 0.12.1."
(defun ein:notebook-ask-before-kill-buffer ()
"Return `nil' to prevent killing the notebook buffer.
Called via `kill-buffer-query-functions'."
(not (and ein:notebook-kill-buffer-ask
(not (or (and ein:notebook-kill-buffer-ask
(ein:worksheet-p ein:%worksheet%) ; it's not `ein:scratchsheet'
(ein:notebook-modified-p)
(not (y-or-n-p "You have unsaved changes. Discard changes?")))))
(not (y-or-n-p
"You have unsaved changes. Discard changes?")))
(when (ein:worksheet-p ein:%worksheet%)
;; To make `ein:worksheet-save-cells' no-op.
(ein:worksheet-detach-from-buffer ein:%worksheet%)
nil))))
(add-hook 'kill-buffer-query-functions 'ein:notebook-ask-before-kill-buffer)

View file

@ -159,6 +159,10 @@ this value."
((buffer-live-p buffer)))
buffer))
(defmethod ein:worksheet-detach-from-buffer ((ws ein:worksheet))
"Deactivate worksheet WS without killing buffer."
(slot-makeunbound ws :ewoc))
(defmethod ein:worksheet--buffer-name ((ws ein:worksheet))
(format ein:worksheet-buffer-name-template
(ein:worksheet-url-or-port ws)