From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#51883: 29.0.50; Command to get accidentally deleted frames back Date: Wed, 19 Jan 2022 20:37:37 +0200 Organization: LINKOV.NET Message-ID: <86lezbwr4p.fsf@mail.linkov.net> References: <87czn1gfb1.fsf@web.de> <87czmlg1rz.fsf@web.de> <227d35a5bc25a5f57453@heytings.org> <87zgppekxe.fsf@web.de> <227d35a5bcdae0a85f4d@heytings.org> <87v90dekii.fsf@web.de> <227d35a5bc14f7b3c75c@heytings.org> <87r1b1ejif.fsf@web.de> <227d35a5bc16d5c159ac@heytings.org> <87fsrg8ep4.fsf@web.de> <87bl22n7ut.fsf@web.de> <877dcqn5kx.fsf@web.de> <86h7bur9yi.fsf@mail.linkov.net> <864k68ujbx.fsf@mail.linkov.net> <861r1aoi9i.fsf@mail.linkov.net> <867daz1jo1.fsf@mail.linkov.net> <83mtjuwm8c.fsf@gnu.org> <86a6fuxkz1.fsf@mail.linkov.net> <83tue2urfo.fsf@gnu.org> <86a6fsnaoi.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27405"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) Cc: michael_heerdegen@web.de, gregory@heytings.org, 51883@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jan 19 19:54:57 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1nAG6j-0006zA-4W for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 19 Jan 2022 19:54:57 +0100 Original-Received: from localhost ([::1]:35064 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nAG6f-00053q-Mj for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 19 Jan 2022 13:54:55 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:36940) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nAFsJ-0000Tq-4F for bug-gnu-emacs@gnu.org; Wed, 19 Jan 2022 13:40:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:34347) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nAFsI-0003ph-BY for bug-gnu-emacs@gnu.org; Wed, 19 Jan 2022 13:40:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nAFsI-0007Xo-At for bug-gnu-emacs@gnu.org; Wed, 19 Jan 2022 13:40:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 19 Jan 2022 18:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51883 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 51883-submit@debbugs.gnu.org id=B51883.164261758528971 (code B ref 51883); Wed, 19 Jan 2022 18:40:02 +0000 Original-Received: (at 51883) by debbugs.gnu.org; 19 Jan 2022 18:39:45 +0000 Original-Received: from localhost ([127.0.0.1]:55483 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nAFs1-0007XC-3n for submit@debbugs.gnu.org; Wed, 19 Jan 2022 13:39:45 -0500 Original-Received: from relay2-d.mail.gandi.net ([217.70.183.194]:48571) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nAFrx-0007Ws-Rv for 51883@debbugs.gnu.org; Wed, 19 Jan 2022 13:39:43 -0500 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id 8A4F240002; Wed, 19 Jan 2022 18:39:34 +0000 (UTC) In-Reply-To: <86a6fsnaoi.fsf@mail.linkov.net> (Juri Linkov's message of "Tue, 18 Jan 2022 20:30:09 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:224627 Archived-At: --=-=-= Content-Type: text/plain >>> >> > I tried to use this, but undelete-frame-mode in the File menu >>> >> > makes no sense: when you mistakenly deleted a frame, you want >>> >> > to undelete it immediately, so you open the File menu, and >>> >> > see the message "No way, you can't undelete the deleted frame, >>> >> > because you were careless and not enabled a special mode". >>> >> > >>> >> > So the most useful case for this feature is to get the >>> >> > accidentally deleted frame back, and it fails to do this. >>> >> > >>> >> > Instead, it allows undeleting 16 frames in a special mode. >>> >> > Is there really a human that can delete 16 frames, and then >>> >> > remember what was on the 16th frame back? >>> >> > >>> >> > Rereading this thread indicates that the only concern about >>> >> > enabling this by default was the memory footprint for remembering >>> >> > 16 frames. OTOH, this feature is really useful for remembering >>> >> > 1 frame. So this is what should be enabled by default: >>> >> >>> >> It seems this is the right thing to do, so now pushed to master. >>> > >>> > I'm sorry, you cannot do that. We discussed this at some length and >>> > reached certain conclusions. Then you come and in effect say those >>> > considerations and discussions make no sense, and you know better? >>> > Let's please respect our discussions and decisions more than that. >>> > And if you want others to respect your opinions, please respect >>> > theirs, even if you disagree. The feature as installed allows you to >>> > customize it to have that mode turned on by default, so you could >>> > easily fix your problem by doing that. >>> > >>> > Specifically to your main argument: it is no different from deleting a >>> > file: unless the user took steps to configure the system to allow >>> > undeleting deleted files, deleted files are lost forever. Moreover, >>> > in the case of an Emacs frame, nothing of terrible importance is >>> > actually lost: the buffers displayed in that frame are still there, >>> > and restoring the deleted frame by hand shouldn't take more than a few >>> > moments. >>> > >>> > So I reverted this changeset. Please in the future don't make such >>> > changes unilaterally. >>> >>> This is not true. This is not a unilateral change. I posted a patch, >>> then waited for comments 3 days, and when no one commented this means >>> that everyone agreed that it's a more reasonable change, then pushed to >>> master. >> >> I guess 3 days is not enough, especially in this time of year. My >> rule of thumb is to wait at least a week, possibly two. >> >> But in any case, the amount of time you waited is not the main issue >> here. The main issue is that we decided to implement this the way we >> did, and you were even part of that discussion. It makes no sense to >> undo all that because you suddenly don't like the results. > > After applying the patch to test whether it correctly restores the tab-bar, > I discovered that the weirdest thing was added to the main menu. > > No other app has such unusual menu item in the File menu > because this feature is useful for everyone. > Just imagine trying to undelete a tab in a web browser, > then failing to do this when the browser requires > to enable a special mode to undelete tabs. We can't afford > to make Emacs more bizarre than it currently is, that > would scare away users. > > Then I recalled that the main argument in the discussion > against enabling this by default was the memory occupied > by 16 deleted frames. > > So to simplify this I proposed a new option with the default value 1 > instead of the hard-coded number 16. Then waited for 3 days > that is standard practice. And no comments means that everyone agreed > with this improvement. Here is the patch that fixes all these problems: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=undelete-frame-max.patch diff --git a/doc/emacs/frames.texi b/doc/emacs/frames.texi index ba58f70caf..c641b8ccb1 100644 --- b/doc/emacs/frames.texi +++ a/doc/emacs/frames.texi @@ -515,12 +515,14 @@ @item C-x 5 u @kindex C-x 5 u @findex undelete-frame -@findex undelete-frame-mode -When @code{undelete-frame-mode} is enabled, undelete one of the 16 -most recently deleted frames. Without a prefix argument, undelete the -most recently deleted frame. With a numerical prefix argument between -1 and 16, where 1 is the most recently deleted frame, undelete the -corresponding deleted frame. +@findex undelete-frame-max +Undelete one of the recently deleted frames. The user option +@code{undelete-frame-max} specifies the maximum number of deleted +frames to keep (the default is 1). Without a prefix argument, +undelete the most recently deleted frame. With a numerical prefix +argument between 1 and the number specified by @code{undelete-frame-max}, +where 1 is the most recently deleted frame, undelete the corresponding +deleted frame. @item C-z @kindex C-z @r{(X windows)} diff --git a/etc/NEWS b/etc/NEWS index fdbfd9b1be..2e748ce7c5 100644 --- b/etc/NEWS +++ a/etc/NEWS @@ -287,11 +287,12 @@ +++ *** Deleted frames can now be undeleted. -The 16 most recently deleted frames can be undeleted with 'C-x 5 u' when -'undelete-frame-mode' is enabled. Without a prefix argument, undelete -the most recently deleted frame. With a numerical prefix argument -between 1 and 16, where 1 is the most recently deleted frame, undelete -the corresponding deleted frame. +The most recently deleted frame can be undeleted with 'C-x 5 u' when +the new user option 'undelete-frame-max' has its default value 1. +Without a prefix argument, undelete the most recently deleted frame. +With a numerical prefix argument between 1 and 'undelete-frame-max', +where 1 is the most recently deleted frame, undelete the corresponding +deleted frame. ** Tab Bars and Tab Lines diff --git a/lisp/frame.el b/lisp/frame.el index 5926a4d748..599ffe591a 100644 --- b/lisp/frame.el +++ a/lisp/frame.el @@ -2529,6 +2529,13 @@ (if iconify (iconify-frame this) (delete-frame this))) (setq this next)))) + +(defcustom undelete-frame-max 1 + "Maximum number of deleted frames before oldest are thrown away." + :type 'integer + :group 'frames + :version "29.1") + (eval-when-compile (require 'frameset)) (defvar undelete-frame--deleted-frames nil @@ -2536,7 +2543,7 @@ (defun undelete-frame--handle-delete-frame (frame) "Save the configuration of frames deleted with `delete-frame'. -Only the 16 most recently deleted frames are saved." +Only the `undelete-frame-max' most recently deleted frames are saved." (when (frame-live-p frame) (setq undelete-frame--deleted-frames (cons @@ -2555,54 +2562,45 @@ (cons '(display . :never) frameset-filter-alist)))) undelete-frame--deleted-frames)) - (if (> (length undelete-frame--deleted-frames) 16) + (if (> (length undelete-frame--deleted-frames) undelete-frame-max) (setq undelete-frame--deleted-frames (butlast undelete-frame--deleted-frames))))) -(define-minor-mode undelete-frame-mode - "Enable the `undelete-frame' command." - :group 'frames - :global t - (if undelete-frame-mode - (add-hook 'delete-frame-functions - #'undelete-frame--handle-delete-frame -75) - (remove-hook 'delete-frame-functions - #'undelete-frame--handle-delete-frame) - (setq undelete-frame--deleted-frames nil))) +(add-hook 'after-init-hook + (lambda () + (add-hook 'delete-frame-functions + #'undelete-frame--handle-delete-frame -75))) (defun undelete-frame (&optional arg) "Undelete a frame deleted with `delete-frame'. -Without a prefix argument, undelete the most recently deleted -frame. -With a numerical prefix argument ARG between 1 and 16, where 1 is -most recently deleted frame, undelete the ARGth deleted frame. +Without a prefix argument, undelete the most recently deleted frame. +With a numerical prefix argument ARG between 1 and `undelete-frame-max', +where 1 is most recently deleted frame, undelete the ARGth deleted frame. When called from Lisp, returns the new frame." (interactive "P") - (if (not undelete-frame-mode) - (user-error "Undelete-Frame mode is disabled") - (if (consp arg) - (user-error "Missing deleted frame number argument") - (let* ((number (pcase arg ('nil 1) ('- -1) (_ arg))) - (frames (frame-list)) - (frameset (nth (1- number) undelete-frame--deleted-frames)) - (graphic (display-graphic-p))) - (if (not (<= 1 number 16)) - (user-error "%d is not a valid deleted frame number argument" - number) - (if (not frameset) - (user-error "No deleted frame with number %d" number) - (if (not (eq graphic (car frameset))) - (user-error - "Cannot undelete a %s display frame on a %s display" - (if graphic "non-graphic" "graphic") - (if graphic "graphic" "non-graphic")) - (setq undelete-frame--deleted-frames - (delq frameset undelete-frame--deleted-frames)) - (frameset-restore (cdr frameset)) - (let ((frame (car (seq-difference (frame-list) frames)))) - (when frame - (select-frame-set-input-focus frame) - frame))))))))) + (if (consp arg) + (user-error "Missing deleted frame number argument") + (let* ((number (pcase arg ('nil 1) ('- -1) (_ arg))) + (frames (frame-list)) + (frameset (nth (1- number) undelete-frame--deleted-frames)) + (graphic (display-graphic-p))) + (if (not (<= 1 number undelete-frame-max)) + (user-error "%d is not a valid deleted frame number argument" + number) + (if (not frameset) + (user-error "No deleted frame with number %d" number) + (if (not (eq graphic (car frameset))) + (user-error + "Cannot undelete a %s display frame on a %s display" + (if graphic "non-graphic" "graphic") + (if graphic "graphic" "non-graphic")) + (setq undelete-frame--deleted-frames + (delq frameset undelete-frame--deleted-frames)) + (frameset-restore (cdr frameset)) + (let ((frame (car (seq-difference (frame-list) frames)))) + (when frame + (select-frame-set-input-focus frame) + frame)))))))) ;;; Window dividers. (defgroup window-divider nil diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el index e5a070b24a..36cbd6a9c5 100644 --- b/lisp/menu-bar.el +++ a/lisp/menu-bar.el @@ -109,14 +109,9 @@ (bindings--define-key menu [separator-tab] menu-bar-separator)) - (bindings--define-key menu [enable-undelete-frame-mode] - '(menu-item "Enable Undeleting Frames" undelete-frame-mode - :visible (null undelete-frame-mode) - :help "Enable undeleting frames in this session")) (bindings--define-key menu [undelete-last-deleted-frame] '(menu-item "Undelete Frame" undelete-frame - :visible (and undelete-frame-mode - (car undelete-frame--deleted-frames)) + :visible (car undelete-frame--deleted-frames) :help "Undelete the most recently deleted frame")) ;; Don't use delete-frame as event name because that is a special diff --git a/src/frame.c b/src/frame.c index 959f0c9c14..e5d74edc16 100644 --- b/src/frame.c +++ a/src/frame.c @@ -2385,7 +2385,7 @@ doc: /* Delete FRAME, eliminating it from use. FRAME must be a live frame and defaults to the selected one. -When `undelete-frame-mode' is enabled, the 16 most recently deleted +When `undelete-frame-max' is more than 0, the most recently deleted frames can be undeleted with `undelete-frame', which see. A frame may not be deleted if its minibuffer serves as surrogate --=-=-=--