From: Drew Adams <drew.adams@oracle.com>
Date: Wed, 1 Sep 2021 09:42:48 +0000 (+0200)
Subject: Add new command `clone-frame'
X-Git-Tag: emacs-28.0.90~1238
X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=2c662e6d66165db8ead2f4d19a61af521807b8ba;p=emacs.git

Add new command `clone-frame'

* doc/emacs/frames.texi (Creating Frames): Document it.

* lisp/frame.el (clone-frame): New command and keystroke (bug#34715).
---

diff --git a/doc/emacs/frames.texi b/doc/emacs/frames.texi
index 22f22efacac..a32181e73be 100644
--- a/doc/emacs/frames.texi
+++ b/doc/emacs/frames.texi
@@ -452,7 +452,14 @@ buffer to select:
 @item C-x 5 2
 @kindex C-x 5 2
 @findex make-frame-command
-Create a new frame (@code{make-frame-command}).
+Create a new frame using the default frame parameters
+(@code{make-frame-command}).
+
+@item C-x 5 c
+@kindex C-x 5 c
+@findex clone-frame
+Create a new frame using the parameters of the current frame
+(@code{clone-frame}).
 
 @item C-x 5 b @var{bufname} @key{RET}
 Select buffer @var{bufname} in another frame.  This runs
diff --git a/etc/NEWS b/etc/NEWS
index 66006db8e0a..0e1edd648d0 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -343,6 +343,11 @@ commands.  The new keystrokes are 'C-x x g' ('revert-buffer-quick'),
 ** Commands 'set-frame-width' and 'set-frame-height' can now get their
 input using the minibuffer.
 
++++
+** New command 'clone-frame' (bound to 'C-x 5 c').
+This is like 'C-x 5 2', but uses the frame parameters of the current
+frame instead of 'default-frame-alist'.
+
 ---
 ** New help window when Emacs prompts before opening a large file.
 Commands like 'find-file' or 'visit-tags-table' ask to visit a file
diff --git a/lisp/frame.el b/lisp/frame.el
index 28601b81a48..f36a34db7d7 100644
--- a/lisp/frame.el
+++ b/lisp/frame.el
@@ -787,6 +787,23 @@ When called from Lisp, returns the new frame."
       (make-frame)
     (select-frame (make-frame))))
 
+(defun clone-frame (&optional frame use-default-parameters)
+  "Make a new frame with the same parameters as FRAME.
+With a prefix arg (USE-DEFAULT-PARAMETERS), use
+`default-frame-alist' instead.
+
+FRAME defaults to the selected frame.  The frame is created on the
+same terminal as FRAME.  If the terminal is a text-only terminal then
+also select the new frame."
+  (interactive "i\nP")
+  (if use-default-parameters
+      (make-frame-command)
+    (let* ((default-frame-alist (frame-parameters frame))
+           (new-frame (make-frame)))
+      (unless (display-graphic-p)
+        (select-frame new-frame))
+      new-frame)))
+
 (defvar before-make-frame-hook nil
   "Functions to run before `make-frame' creates a new frame.")
 
@@ -2807,6 +2824,7 @@ See also `toggle-frame-maximized'."
 (define-key ctl-x-5-map "0" #'delete-frame)
 (define-key ctl-x-5-map "o" #'other-frame)
 (define-key ctl-x-5-map "5" #'other-frame-prefix)
+(define-key ctl-x-5-map "c" #'clone-frame)
 (define-key global-map [f11] #'toggle-frame-fullscreen)
 (define-key global-map [(meta f10)] #'toggle-frame-maximized)
 (define-key esc-map    [f10]        #'toggle-frame-maximized)