From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michal Nazarewicz Newsgroups: gmane.emacs.devel Subject: [PATCH] files.el: avoid asking whether to kill Emacs multiple times Date: Thu, 29 Jan 2015 15:06:49 +0100 Message-ID: <1422540409-4134-1-git-send-email-mpn@google.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1422540477 9991 80.91.229.3 (29 Jan 2015 14:07:57 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 29 Jan 2015 14:07:57 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jan 29 15:07:57 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YGplC-0002Xq-6s for ged-emacs-devel@m.gmane.org; Thu, 29 Jan 2015 15:07:54 +0100 Original-Received: from localhost ([::1]:59901 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGplB-0004Dm-Cm for ged-emacs-devel@m.gmane.org; Thu, 29 Jan 2015 09:07:53 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55242) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGpl7-0004CK-1Z for emacs-devel@gnu.org; Thu, 29 Jan 2015 09:07:50 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YGpl2-0005eo-MQ for emacs-devel@gnu.org; Thu, 29 Jan 2015 09:07:49 -0500 Original-Received: from mail-wi0-x236.google.com ([2a00:1450:400c:c05::236]:61190) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGpl2-0005ea-Bf for emacs-devel@gnu.org; Thu, 29 Jan 2015 09:07:44 -0500 Original-Received: by mail-wi0-f182.google.com with SMTP id n3so24974871wiv.3 for ; Thu, 29 Jan 2015 06:07:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; bh=KfU9DJNuJumJdGOb3we5midytlst8j5Wh97c6wrN5wQ=; b=M4Q/DmDgv0y6oIih6fKR/IBRCjcBo6TDuLEmzE/rlFwQJjuHgHZL9JG2z8b+ftecST ZECkcQ3L3RYC83LqbBPPDw91S9WcuMHl0YcVbe9kXuAM7Eau7lS7i3VkTInZTiQ1piaG gDoxgZYeg4fM2i8JZ90WMwGHtlX45UF8TNdwnFvmIQ8GtxKLxDmVEX3D9RjnjBl9rXex iq4GGFZSUSej1bjkYqO02kXkGmlP0gMU29v6UV5nME47L6TBavnlvfxR2qCzcSJpILon 2/uVqvvdeTE3L8E4rcxdkN7DZcrU55rBdIcs4vXqJOUlSN11rJO18P1MyWAme4pvdDHu w1IA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-type:content-transfer-encoding; bh=KfU9DJNuJumJdGOb3we5midytlst8j5Wh97c6wrN5wQ=; b=AvTiK42vR0W9QgB6hnFqkCggG3otV2GTSAY29PCobfrXXu0pBDBmB3mqyNFgWq+Kii WjphA1lD4diaDTCWkzSjRFh0DP7ukDOQBjbBOmThO8TE3E6dlnQJIALaSdq7tmvm4rhS tc4ukzKVKPLs/2gUFC2xwVLjpYqaAT9XVU2YXUoWEJGyiLXTs4Jab3bmSf6RWbSUjA7H D3+zv8dmu/nzGuFTdhqgwPDSXFu1BoC3eLDCQqUk4vMUwZp62+39lOid3wJ0u+kj+Sjn YCB4MpVo+35w5PPQrA4eHOAOU0zcY20kMb6xPgBh0Ik+/sFFrlcRvaQfonCXEbaJHM6M 9MLA== X-Gm-Message-State: ALoCoQkpWj20OfdztekiJ0a4VOnen+Y7U5+ukxEUwneqL6GICSj59ACQREfePoYJv0Whq8usqrw3 X-Received: by 10.180.206.19 with SMTP id lk19mr1292667wic.83.1422540463143; Thu, 29 Jan 2015 06:07:43 -0800 (PST) Original-Received: from mpn-glaptop.roam.corp.google.com (166-227.197-178.cust.bluewin.ch. [178.197.227.166]) by mx.google.com with ESMTPSA id i3sm2620668wie.23.2015.01.29.06.07.22 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Jan 2015 06:07:41 -0800 (PST) X-Mailer: git-send-email 2.2.0.rc0.207.ga3a616c X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::236 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:181977 Archived-At: From: Michal Nazarewicz * lisp/files.el (save-buffers-kill-emacs): If `confirm-kill-emacs' is set, but user has just been asked whether they really want to kill Emacs (for example with a ‘Modified buffers exist; exit anyway?’ prompt) , do not ask them for another confirmation. However, apply this exception only if `confirm-kill-emacs' is 'yes-or-no-p or 'y-or-n-p, otherwise this change might errenously prevent some user defined function from being run (adding such a function to `kill-emacs-query-functions' is probably better option, but we don’t want to break any usage even if it’s incorrect). --- lisp/files.el | 64 ++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/lisp/files.el b/lisp/files.el index e9632ed..7d94bc1 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -6590,35 +6590,41 @@ (defun save-buffers-kill-emacs (&optional arg) if any returns nil. If `confirm-kill-emacs' is non-nil, calls it." (interactive "P") (save-some-buffers arg t) - (and (or (not (memq t (mapcar (function - (lambda (buf) (and (buffer-file-name buf) - (buffer-modified-p buf)))) - (buffer-list)))) - (yes-or-no-p "Modified buffers exist; exit anyway? ")) - (or (not (fboundp 'process-list)) - ;; process-list is not defined on MSDOS. - (let ((processes (process-list)) - active) - (while processes - (and (memq (process-status (car processes)) '(run stop open listen)) - (process-query-on-exit-flag (car processes)) - (setq active t)) - (setq processes (cdr processes))) - (or (not active) - (with-current-buffer-window - (get-buffer-create "*Process List*") nil - #'(lambda (window _value) - (with-selected-window window - (unwind-protect - (yes-or-no-p "Active processes exist; kill them and exit anyway? ") - (when (window-live-p window) - (quit-restore-window window 'kill))))) - (list-processes t))))) - ;; Query the user for other things, perhaps. - (run-hook-with-args-until-failure 'kill-emacs-query-functions) - (or (null confirm-kill-emacs) - (funcall confirm-kill-emacs "Really exit Emacs? ")) - (kill-emacs))) + (let (asked) + (and + (or (not (memq t (mapcar (function + (lambda (buf) (and (buffer-file-name buf) + (buffer-modified-p buf)))) + (buffer-list)))) + (progn (setq asked t) + (yes-or-no-p "Modified buffers exist; exit anyway? "))) + (or (not (fboundp 'process-list)) + ;; process-list is not defined on MSDOS. + (let ((processes (process-list)) + active) + (while processes + (and (memq (process-status (car processes)) '(run stop open listen)) + (process-query-on-exit-flag (car processes)) + (setq active t)) + (setq processes (cdr processes))) + (or (not active) + (with-current-buffer-window + (get-buffer-create "*Process List*") nil + #'(lambda (window _value) + (with-selected-window window + (unwind-protect + (progn + (setq asked t) + (yes-or-no-p "Active processes exist; kill them and exit anyway? ")) + (when (window-live-p window) + (quit-restore-window window 'kill))))) + (list-processes t))))) + ;; Query the user for other things, perhaps. + (run-hook-with-args-until-failure 'kill-emacs-query-functions) + (or (null confirm-kill-emacs) + (and asked (memq confirm-kill-emacs '(yes-or-no-p y-or-n-p))) + (funcall confirm-kill-emacs "Really exit Emacs? ")) + (kill-emacs)))) (defun save-buffers-kill-terminal (&optional arg) "Offer to save each buffer, then kill the current connection. -- 2.2.0.rc0.207.ga3a616c