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: Sun, 30 Jan 2022 18:39:16 +0200 Organization: LINKOV.NET Message-ID: <86czk9kxm8.fsf@mail.linkov.net> References: <87czn1gfb1.fsf@web.de> <838rxo0zk7.fsf@gnu.org> 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="26835"; 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 , 51883@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jan 30 17:43:58 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 1nEDJ0-0006jL-J7 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 30 Jan 2022 17:43:58 +0100 Original-Received: from localhost ([::1]:45806 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nEDIz-0006fq-KT for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 30 Jan 2022 11:43:57 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:47746) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nEDH9-0004bd-8K for bug-gnu-emacs@gnu.org; Sun, 30 Jan 2022 11:42:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:44570) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nEDH8-0004wL-Ix for bug-gnu-emacs@gnu.org; Sun, 30 Jan 2022 11:42:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nEDH8-0005SI-CT for bug-gnu-emacs@gnu.org; Sun, 30 Jan 2022 11:42: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: Sun, 30 Jan 2022 16:42: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.164356089020927 (code B ref 51883); Sun, 30 Jan 2022 16:42:02 +0000 Original-Received: (at 51883) by debbugs.gnu.org; 30 Jan 2022 16:41:30 +0000 Original-Received: from localhost ([127.0.0.1]:37473 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nEDGc-0005RT-7p for submit@debbugs.gnu.org; Sun, 30 Jan 2022 11:41:30 -0500 Original-Received: from relay12.mail.gandi.net ([217.70.178.232]:49999) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nEDGZ-0005RE-VA for 51883@debbugs.gnu.org; Sun, 30 Jan 2022 11:41:28 -0500 Original-Received: (Authenticated sender: juri@linkov.net) by relay12.mail.gandi.net (Postfix) with ESMTPSA id A1C08200009; Sun, 30 Jan 2022 16:41:19 +0000 (UTC) In-Reply-To: (Stefan Monnier via's message of "Fri, 21 Jan 2022 12:52:35 -0500") 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:225612 Archived-At: --=-=-= Content-Type: text/plain > Eli Zaretskii [2021-11-16 19:40:08] wrote: >>> +(add-hook 'delete-frame-functions #'undeleted-frame--save-deleted-frame) >> >> I'd rather we didn't do that by default. Several reasons: >> >> . the startup code deletes the terminal frame, so the above means we >> will always load frameset, which is not a small package, at >> startup, even if the user has no use for this functionality > > Clearly we should avoid putting the special initial-frame in the undo > log since we don't want (and can't) recreate it later anyway. This is fixed now. > But as for loading the package, the problem is more general in the sense > that maybe we should refrain from loading the package just because > a frame is deleted. > > So maybe we should change the code so the hook's function doesn't > require loading `frameset.el`. AFAICT fundamentally, the only function > from `frameset.el` that it needs is `frameset-filter-params`, so maybe > we should move some of that code to `frame.el`. Now the undelete-frame feature doesn't load frameset.el anymore. So all concerns raised by Eli are addressed now that make possible to enable it by default as was discussed on emacs-devel: --=-=-= 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 29edbe9863..39b38a95d3 100644 --- a/doc/emacs/frames.texi +++ b/doc/emacs/frames.texi @@ -515,12 +515,14 @@ Frame Commands @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 19d23e8943..385ddb0262 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -327,11 +327,13 @@ height use 'window-height' in combination with 'body-lines'. +++ *** 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' +if the new user option 'undelete-frame-max' is a positive number. +This option specifies the maximum number of closed frames to remember. +The default is 1. Without a prefix argument, undelete the most +recently deleted frame. With a numerical prefix argument between 1 +and the value of '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 d39597d0af..143c51b98c 100644 --- a/lisp/frame.el +++ b/lisp/frame.el @@ -2530,12 +2530,19 @@ delete-other-frames (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") + (defvar undelete-frame--deleted-frames nil "Internal variable used by `undelete-frame--save-deleted-frame'.") (defun undelete-frame--save-deleted-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 (and after-init-time (frame-live-p frame)) (setq undelete-frame--deleted-frames (cons @@ -2554,53 +2561,41 @@ undelete-frame--save-deleted-frame (frame-parameters frame)) (window-state-get (frame-root-window frame))) 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--save-deleted-frame -75) - (remove-hook 'delete-frame-functions - #'undelete-frame--save-deleted-frame) - (setq undelete-frame--deleted-frames nil))) +(add-hook 'delete-frame-functions #'undelete-frame--save-deleted-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))) - (frame-data (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 frame-data) - (user-error "No deleted frame with number %d" number) - (if (not (eq graphic (nth 0 frame-data))) - (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 frame-data undelete-frame--deleted-frames)) - (let* ((default-frame-alist (nth 1 frame-data)) - (frame (make-frame))) - (window-state-put (nth 2 frame-data) (frame-root-window frame) 'safe) - (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))) + (frame-data (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 frame-data) + (user-error "No deleted frame with number %d" number) + (if (not (eq graphic (nth 0 frame-data))) + (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 frame-data undelete-frame--deleted-frames)) + (let* ((default-frame-alist (nth 1 frame-data)) + (frame (make-frame))) + (window-state-put (nth 2 frame-data) (frame-root-window frame) 'safe) + (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 b6dbf209ec..df55b3be89 100644 --- a/lisp/menu-bar.el +++ b/lisp/menu-bar.el @@ -108,15 +108,9 @@ menu-bar-file-menu (bindings--define-key menu [separator-tab] menu-bar-separator) - (bindings--define-key menu [undelete-frame-mode] - '(menu-item "Allow Undeleting Frames" undelete-frame-mode - :help "Allow frames to be restored after deletion" - :button (:toggle . undelete-frame-mode))) - (bindings--define-key menu [undelete-last-deleted-frame] '(menu-item "Undelete Frame" undelete-frame - :enable (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 f94dff0a60..1d0dcf6278 100644 --- a/src/frame.c +++ b/src/frame.c @@ -2385,7 +2385,7 @@ DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "", 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 --=-=-=--