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: [PATCHv5 1/4] `kill-buffer' runs query functions before checking buffer modification. Date: Fri, 28 Jun 2013 16:40:52 +0200 Message-ID: References: NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1372430480 26297 80.91.229.3 (28 Jun 2013 14:41:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 28 Jun 2013 14:41:20 +0000 (UTC) Cc: martin rudalics , emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jun 28 16:41:21 2013 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 1UsZrU-0001T3-QW for ged-emacs-devel@m.gmane.org; Fri, 28 Jun 2013 16:41:21 +0200 Original-Received: from localhost ([::1]:58600 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UsZrU-0007ns-E9 for ged-emacs-devel@m.gmane.org; Fri, 28 Jun 2013 10:41:20 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46764) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UsZrO-0007kN-69 for emacs-devel@gnu.org; Fri, 28 Jun 2013 10:41:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UsZrI-0001ra-1A for emacs-devel@gnu.org; Fri, 28 Jun 2013 10:41:14 -0400 Original-Received: from mail-ea0-x22a.google.com ([2a00:1450:4013:c01::22a]:56080) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UsZrH-0001rW-Ok for emacs-devel@gnu.org; Fri, 28 Jun 2013 10:41:07 -0400 Original-Received: by mail-ea0-f170.google.com with SMTP id h10so1120034eaj.1 for ; Fri, 28 Jun 2013 07:41:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :in-reply-to:references; bh=dg6rxi4guh1EOITW4okOrMiSUWb99iieiAqgHXkoFx8=; b=MBhCehWNzLcPvf2xFcgS2ACzCAYWDv3WCW2nJWVznmgJ2Z/rU63bqkMBrc1itds3MH DpWOMlqhKgLJsYv1tT69C0ynAI4I0RDaKxK0ugDHw8TAEDEUAESpqmh/bTUekJRy8+xp WBUho1nmQZ+/LMt6Wmda6YE/Ig8yyUf+BIAZEQ5659ZRvB8uDZNtNbQThhiVNv/G9QP0 jcxxC7gTkyo9CMAg9GgSWP3Yio6xCpYFgVM576MaBDCHOUPBz6fhYq7PsV6JZufCLwSf CphsAp/yiZZ8UauYm20ewy17ckHb/7oqahaKlL1qbrkQLYUpjOUOBPwYKEwv+snh9i5g Jnfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :in-reply-to:references:x-gm-message-state; bh=dg6rxi4guh1EOITW4okOrMiSUWb99iieiAqgHXkoFx8=; b=F4wqDoJowkiYld54kOPVoUGkiLiXKr/Yvcm6m5NEMTd/SuQlOYNuTtB1Q5qvSXKjUo Fyc5PyWcV1W/C0WAj5MkdRhOzrnP60loVFzsVPhalEQXcAIMxHP7Lz8TuHXbIH3NbwwZ 2XnyGAaUc82YjBINhkNYBLQtpmRsrWCkvBZ59ho8z1QTk8DqK9SLT6+G5nendX7Vb1HQ iDpYyvv28VhRh8Cpoy8rO/9v2YJAnU0dY6TN6hx6am/80DF2o9AYqYVwsckIJGSD1JtI DC/n+g0d2RiZpenO48UqlD48sCt+dGtMnPLkTFbnaQZKvFvqBymWPfQnJT3CYeklSiVh 5soQ== X-Received: by 10.15.108.8 with SMTP id cc8mr14012610eeb.65.1372430466912; Fri, 28 Jun 2013 07:41:06 -0700 (PDT) Original-Received: from mpn-glaptop.corp.google.com ([2620:0:105f:301:3899:bd8c:7f4a:bec8]) by mx.google.com with ESMTPSA id i2sm10938994eeu.4.2013.06.28.07.41.05 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 28 Jun 2013 07:41:05 -0700 (PDT) X-Mailer: git-send-email 1.8.3.1 In-Reply-To: In-Reply-To: Original-References: X-Gm-Message-State: ALoCoQkBWX/6hwX62L1T0FhdT6lvU01WcfVcQvddzg174DxDODihVdEbr9xPVkF2kVz3WfTlRkYbjWxfpHsgS1eMarWoMnwAwidWKiA4BXYqqms2D+fHLg8fgELx4iLD1lqNRjyJqtpnG97RCBOMOTgfPioFQPcTC1XA233/h623tZ8yxfu2teapTQOWXXic8+7BAWhnF7l/ X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4013:c01::22a 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:161216 Archived-At: From: Michal Nazarewicz * buffer.c (FKill_buffer): Run `kill-buffer-query-functions' before checking whether buffer is modified. This lets `kill-buffer-query-functions' cancel killing of the buffer or save its content before `kill-buffer' asks user the "Buffer %s modified; kill anyway?" question. --- doc/lispref/buffers.texi | 2 +- src/ChangeLog | 8 ++++++++ src/buffer.c | 28 ++++++++++++++++------------ 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/doc/lispref/buffers.texi b/doc/lispref/buffers.texi index 7ed1876..e79c86d 100644 --- a/doc/lispref/buffers.texi +++ b/doc/lispref/buffers.texi @@ -1064,7 +1064,7 @@ Buffer foo.changed modified; kill anyway? (yes or no) @kbd{yes} @end deffn @defvar kill-buffer-query-functions -After confirming unsaved changes, @code{kill-buffer} calls the functions +Before confirming unsaved changes, @code{kill-buffer} calls the functions in the list @code{kill-buffer-query-functions}, in order of appearance, with no arguments. The buffer being killed is the current buffer when they are called. The idea of this feature is that these functions will diff --git a/src/ChangeLog b/src/ChangeLog index e404cdb..a3af8d1 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2013-06-28 Michal Nazarewicz + + * buffer.c (FKill_buffer): Run `kill-buffer-query-functions' + before checking whether buffer is modified. This lets + `kill-buffer-query-functions' cancel killing of the buffer or save + its content before `kill-buffer' asks user the "Buffer %s + modified; kill anyway?" question. + 2013-06-28 Paul Eggert * image.c (x_from_xcolors): Remove unused local. diff --git a/src/buffer.c b/src/buffer.c index 08299da..ad670e0 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1734,18 +1734,6 @@ cleaning up all windows currently displaying the buffer to be killed. */) if (!BUFFER_LIVE_P (b)) return Qnil; - /* Query if the buffer is still modified. */ - if (INTERACTIVE && !NILP (BVAR (b, filename)) - && BUF_MODIFF (b) > BUF_SAVE_MODIFF (b)) - { - GCPRO1 (buffer); - tem = do_yes_or_no_p (format2 ("Buffer %s modified; kill anyway? ", - BVAR (b, name), make_number (0))); - UNGCPRO; - if (NILP (tem)) - return Qnil; - } - /* Run hooks with the buffer to be killed the current buffer. */ { ptrdiff_t count = SPECPDL_INDEX (); @@ -1761,6 +1749,22 @@ cleaning up all windows currently displaying the buffer to be killed. */) if (NILP (tem)) return unbind_to (count, Qnil); + /* Query if the buffer is still modified. */ + if (INTERACTIVE && !NILP (BVAR (b, filename)) + && BUF_MODIFF (b) > BUF_SAVE_MODIFF (b)) + { + GCPRO1 (buffer); + tem = do_yes_or_no_p (format2 ("Buffer %s modified; kill anyway? ", + BVAR (b, name), make_number (0))); + UNGCPRO; + if (NILP (tem)) + return unbind_to (count, Qnil); + } + + /* If the hooks have killed the buffer, exit now. */ + if (!BUFFER_LIVE_P (b)) + return unbind_to (count, Qt); + /* Then run the hooks. */ Frun_hooks (1, &Qkill_buffer_hook); unbind_to (count, Qnil); -- 1.8.3.1