From 66cfbb2563872593766fea9a402b00cea13fec7e Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 11 Jun 2017 14:05:14 +0200 Subject: [PATCH] Fix quit confirmations in daemon; add for frames + Add quit confirmation when closing a frame with real buffers + Ensure quit confirmations also work in daemon frames (tty or gui) --- CHANGELOG.org | 3 +++ core/autoload/ui.el | 9 +++++++++ core/core-ui.el | 19 ++++++++++++++++--- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.org b/CHANGELOG.org index 972950d5b..3da3c9fe0 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -68,6 +68,9 @@ + =tools/password-store= -- Emacs as a password manager, using [[https://www.passwordstore.org/][pass]] as a backend. + =app/irc= -- Emacs as an IRC client, using circe (contributed by [[https://github.com/bandresen][brandresen]]) + =core= + + =core-ui= + + Add quit confirmation when trying to close a frame that contains real buffers. + + Fix quit confirmations for clients connected to ~emacs --daemon~ with ~emacsclient~. + =core-packages= + When a quelpa package is deleted, its build repo (in ~quelpa-build-dir~) is now deleted with it. + =feature= diff --git a/core/autoload/ui.el b/core/autoload/ui.el index 82cc395ab..222e80dab 100644 --- a/core/autoload/ui.el +++ b/core/autoload/ui.el @@ -50,3 +50,12 @@ window changes before then, the undo expires." (doom-resize-window (truncate (/ (frame-width) 1.2)) t) (doom-resize-window (truncate (/ (frame-height) 1.2))) t))) + +;;;###autoload +(defun doom/delete-frame () + "Delete the current frame, but ask for confirmation if it isn't empty." + (interactive) + (if (cdr (frame-list)) + (when (doom-quit-p "Close frame?") + (delete-frame)) + (save-buffers-kill-emacs))) diff --git a/core/core-ui.el b/core/core-ui.el index f76a7401c..ad96d340b 100644 --- a/core/core-ui.el +++ b/core/core-ui.el @@ -34,12 +34,23 @@ pos-tip-border-width 1 ;; no beeping or blinking please ring-bell-function #'ignore - visible-bell nil - ;; Ask for confirmation on quit only if real buffers exist - confirm-kill-emacs (lambda (_) (if (doom-real-buffers-list) (y-or-n-p "››› Quit?") t))) + visible-bell nil) (fset #'yes-or-no-p #'y-or-n-p) ; y/n instead of yes/no +;; Ask for confirmation when trying to kill emacs or close a frame that has real +;; buffers open in it. +(defun doom-quit-p (&optional prompt) + "Return t if this session should be killed; prompts the user for +confirmation." + (interactive) + (if (ignore-errors (doom-real-buffers-list)) + (or (yes-or-no-p (format "››› %s" (or prompt "Quit Emacs?"))) + (ignore (message "Aborted"))) + t)) +(setq confirm-kill-emacs nil) +(add-hook 'kill-emacs-query-functions #'doom-quit-p) + ;; show typed keystrokes in minibuffer (setq echo-keystrokes 0.02) ;; ...but hide them while isearch is active @@ -119,6 +130,8 @@ mode is detected.") ;; Bootstrap ;; +(global-set-key [remap delete-frame] #'doom/delete-frame) + ;; auto-enabled in Emacs 25+; I'd rather enable it manually (global-eldoc-mode -1)