diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el index e88bcac0da..7185cd52e8 100644 --- a/lisp/tab-bar.el +++ b/lisp/tab-bar.el @@ -481,7 +481,7 @@ tab-bar-new-tab-choice if such buffer exists, or switch to a buffer visiting the file or directory that the string specifies. If the value is a function, call it with no arguments and switch to the buffer that it returns. -If nil, duplicate the contents of the tab that was active +If `clone', duplicate the contents of the tab that was active before calling the command that adds a new tab." :type '(choice (const :tag "Current buffer" t) (const :tag "Current window" window) @@ -489,7 +489,7 @@ tab-bar-new-tab-choice (directory :tag "Directory" :value "~/") (file :tag "File" :value "~/.emacs") (function :tag "Function") - (const :tag "Duplicate tab" nil)) + (const :tag "Duplicate tab" clone)) :group 'tab-bar :version "27.1") @@ -1367,14 +1367,19 @@ tab-bar-new-tab-to (select-window (minibuffer-selected-window))) ;; Remove window parameters that can cause problems ;; with `delete-other-windows' and `split-window'. - (set-window-parameter nil 'window-atom nil) - (set-window-parameter nil 'window-side nil) + (unless (eq tab-bar-new-tab-choice 'clone) + (set-window-parameter nil 'window-atom nil) + (set-window-parameter nil 'window-side nil)) (let ((ignore-window-parameters t)) - (delete-other-windows) - (unless (eq tab-bar-new-tab-choice 'window) - ;; Create a new window to get rid of old window parameters - ;; (e.g. prev/next buffers) of old window. - (split-window) (delete-window))) + (if (eq tab-bar-new-tab-choice 'clone) + (window-state-put (window-state-get)) + (delete-other-windows) + (if (eq tab-bar-new-tab-choice 'window) + ;; TODO: this doesn't create a new window + (window-state-put (window-state-get (selected-window)) (selected-window)) + ;; Create a new window to get rid of old window parameters + ;; (e.g. prev/next buffers) of old window. + (split-window) (delete-window)))) (let ((buffer (if (functionp tab-bar-new-tab-choice) @@ -1453,7 +1458,7 @@ tab-bar-duplicate-tab "Clone the current tab to ARG positions to the right. ARG and FROM-NUMBER have the same meaning as in `tab-bar-new-tab'." (interactive "P") - (let ((tab-bar-new-tab-choice nil) + (let ((tab-bar-new-tab-choice 'clone) (tab-bar-new-tab-group t)) (tab-bar-new-tab arg from-number)))