From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Oliver Taylor Newsgroups: gmane.emacs.devel Subject: Variable for Confirming Killing a Buffer Date: Thu, 2 Dec 2021 13:06:52 -0800 Message-ID: <9EA40AE1-5B31-45D9-AF71-17BB3C6AB8A3@me.com> Mime-Version: 1.0 (Mac OS X Mail 15.0 \(3693.20.0.1.32\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4881"; mail-complaints-to="usenet@ciao.gmane.io" To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Dec 02 22:32:50 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1msthA-00011j-V5 for ged-emacs-devel@m.gmane-mx.org; Thu, 02 Dec 2021 22:32:48 +0100 Original-Received: from localhost ([::1]:37908 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1msth9-0008Cr-QI for ged-emacs-devel@m.gmane-mx.org; Thu, 02 Dec 2021 16:32:47 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:48666) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mstIB-0001Te-BH for emacs-devel@gnu.org; Thu, 02 Dec 2021 16:06:59 -0500 Original-Received: from mr85p00im-ztdg06011201.me.com ([17.58.23.181]:46623) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mstI9-000099-3c for emacs-devel@gnu.org; Thu, 02 Dec 2021 16:06:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1638479214; bh=jyrbR2TM+q4zSJs5Vm76z8Aqdm/kyZctsC8UR+9wvEA=; h=From:Content-Type:Mime-Version:Subject:Message-Id:Date:To; b=TFnNqgwT5DxalPRrBRTqh/fJDcKe/jjhqZMCP0vB5udwWm0mdQoCGn1Jk2AKBhadE oh4BWqC5BqT956PDOcKl0mBL1THj35vJNXOFG+RdaHE8Q2f84xV53nZNq5/VCNuibu Lau5KUWSxZcyTzy6e24IiNQg9kONy2TUJ03Se76H9+Kxou0nXYVZgbABEWFU9LeuNB 5rVEhXiCMbWf09JcJqOQquhI9kVx1dz0djHFIlVJHMgmQIaJbFG7i9zTFfcDrx41ot Z4AgftHZbW58n/YbrcccjrDkskkvmXMUH0aO8kCxJIPZKGgdpFGPL3qkl2tKVN5H13 03Z3/Ut9qxM8w== Original-Received: from smtpclient.apple (071-084-214-239.biz.spectrum.com [71.84.214.239]) by mr85p00im-ztdg06011201.me.com (Postfix) with ESMTPSA id DA5B4400770 for ; Thu, 2 Dec 2021 21:06:53 +0000 (UTC) X-Mailer: Apple Mail (2.3693.20.0.1.32) X-Proofpoint-Virus-Version: =?UTF-8?Q?vendor=3Dfsecure_engine=3D1.1.170-22c6f66c430a71ce266a39bfe25bc?= =?UTF-8?Q?2903e8d5c8f:6.0.425,18.0.790,17.0.607.475.0000000_definitions?= =?UTF-8?Q?=3D2021-12-02=5F15:2021-12-02=5F01,2021-12-02=5F15,2020-04-07?= =?UTF-8?Q?=5F01_signatures=3D0?= X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 adultscore=0 bulkscore=0 malwarescore=0 suspectscore=0 mlxlogscore=473 clxscore=1011 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2112020133 Received-SPF: pass client-ip=17.58.23.181; envelope-from=olivertaylor@me.com; helo=mr85p00im-ztdg06011201.me.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 02 Dec 2021 16:30:47 -0500 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:280790 Archived-At: Emacs asks for confirmation when killing modified file-visiting buffers, = but does not do so for non-file-visiting buffers. The option `buffer-offer-save' tells Emacs to prompt to you save = modified non-file-visiting buffers when EXITING Emacs, but no such option exists = for killing buffers (as described in the docstring for `buffer-offer-save'). I=E2=80=99ve wanted this feature for a while, and managed to create a = working solution with this: -------------------------------- (defvar-local buffer-confirm-kill nil "Non-nil means confirm killing buffer when modified. Variable is checked by `buffer-confirm-kill-p'.") (defun buffer-confirm-kill-p () "Return nil if buffer is modified and `buffer-confirm-kill' is t. This function is designed to be called from = `kill-buffer-query-functions'." (if (and (buffer-modified-p) buffer-confirm-kill) (yes-or-no-p (format "Buffer %S is modified; kill anyway? " (buffer-name))) t)) (add-hook 'kill-buffer-query-functions #'buffer-confirm-kill-p) -------------------------------- Now, doing (setq-local buffer-confirm-kill t) will prevent accidental = data loss. It=E2=80=99s been so useful that I wonder if something like this = shouldn=E2=80=99t just be part of Emacs itself. I just had a new baby so I can=E2=80=99t promise to keep up with = responses to this thread, but I wanted to post a first draft of this now, both to get = feedback on the idea, and to enable anyone who might have the urge to run with = the idea. I=E2=80=99d love to turn it into a proper submission myself, but I = might have to wait until I=E2=80=99m sleeping through the night!