mirror of
https://github.com/vale981/emacs-ipython-notebook
synced 2025-03-06 09:31:39 -05:00
Improve ein:notebook-ask-before-kill-emacs
It was needed to answer `y' when killing Emacs and there exists unsaved buffers. This change eliminate the need for that by killing buffers forcefully.
This commit is contained in:
parent
422adbdd2b
commit
7b93f7c647
1 changed files with 17 additions and 4 deletions
|
@ -990,10 +990,17 @@ Examples:
|
||||||
(or (ein:$notebook-dirty ein:notebook)
|
(or (ein:$notebook-dirty ein:notebook)
|
||||||
(buffer-modified-p))))))
|
(buffer-modified-p))))))
|
||||||
|
|
||||||
|
(defcustom ein:notebook-kill-buffer-ask t
|
||||||
|
"Whether EIN should ask before killing unsaved notebook buffer."
|
||||||
|
:type '(choice (const :tag "Yes" t)
|
||||||
|
(const :tag "No" nil))
|
||||||
|
:group 'ein)
|
||||||
|
|
||||||
(defun ein:notebook-ask-before-kill-buffer ()
|
(defun ein:notebook-ask-before-kill-buffer ()
|
||||||
"Return `nil' to prevent killing the notebook buffer.
|
"Return `nil' to prevent killing the notebook buffer.
|
||||||
Called via `kill-buffer-query-functions'."
|
Called via `kill-buffer-query-functions'."
|
||||||
(not (and (ein:notebook-modified-p)
|
(not (and ein:notebook-kill-buffer-ask
|
||||||
|
(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?")))))
|
||||||
|
|
||||||
(add-hook 'kill-buffer-query-functions 'ein:notebook-ask-before-kill-buffer)
|
(add-hook 'kill-buffer-query-functions 'ein:notebook-ask-before-kill-buffer)
|
||||||
|
@ -1016,9 +1023,15 @@ Called via `kill-emacs-query-functions'."
|
||||||
(ein:notebook-opened-buffers))))
|
(ein:notebook-opened-buffers))))
|
||||||
(if (null unsaved)
|
(if (null unsaved)
|
||||||
t
|
t
|
||||||
|
(let ((answer
|
||||||
(y-or-n-p
|
(y-or-n-p
|
||||||
(format "You have %s unsaved notebook(s). Discard changes?"
|
(format "You have %s unsaved notebook(s). Discard changes?"
|
||||||
(length unsaved))))))
|
(length unsaved)))))
|
||||||
|
;; kill all unsaved buffers forcefully
|
||||||
|
(when answer
|
||||||
|
(let ((ein:notebook-kill-buffer-ask nil))
|
||||||
|
(mapc #'kill-buffer unsaved)))
|
||||||
|
answer))))
|
||||||
|
|
||||||
(add-hook 'kill-emacs-query-functions 'ein:notebook-ask-before-kill-emacs)
|
(add-hook 'kill-emacs-query-functions 'ein:notebook-ask-before-kill-emacs)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue