From 0c341e6e84101251c0e40300519869f24415600d Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Sun, 3 Oct 2021 20:16:32 +0300 Subject: [PATCH] * lisp/tab-bar.el (tab-bar-detach-tab): Handle frame selected by make-frame. (tab-bar-move-window-to-tab): New command. (tab-bar-new-tab-to): Handle the value 'window' of tab-bar-new-tab-choice. https://lists.gnu.org/archive/html/emacs-devel/2021-09/msg02197.html --- lisp/tab-bar.el | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el index 634328e223b..68afb539fa3 100644 --- a/lisp/tab-bar.el +++ b/lisp/tab-bar.el @@ -1211,13 +1211,26 @@ Interactively, ARG selects the ARGth different frame to move to." "Detach tab number FROM-NUMBER to a new frame. Interactively or without argument, detach current tab." (interactive (list (1+ (tab-bar--current-tab-index)))) - (let* ((tab (nth (1- (or from-number 1)) (funcall tab-bar-tabs-function))) - (tab-name (alist-get 'name tab)) + (let* ((tabs (funcall tab-bar-tabs-function)) + (tab-index (1- (or from-number (1+ (tab-bar--current-tab-index tabs))))) + (tab-name (alist-get 'name (nth tab-index tabs))) + ;; On some window managers, `make-frame' selects the new frame, + ;; so previously selected frame is saved to `from-frame'. + (from-frame (selected-frame)) (new-frame (make-frame `((name . ,tab-name))))) - (tab-bar-move-tab-to-frame nil nil from-number new-frame nil) + (tab-bar-move-tab-to-frame nil from-frame from-number new-frame nil) (with-selected-frame new-frame (tab-bar-close-tab)))) +(defun tab-bar-move-window-to-tab () + "Detach the selected window to a new tab." + (interactive) + (let ((tab-bar-new-tab-choice 'window)) + (tab-bar-new-tab)) + (tab-bar-switch-to-recent-tab) + (delete-window) + (tab-bar-switch-to-recent-tab)) + (defcustom tab-bar-new-tab-to 'right "Defines where to create a new tab. @@ -1264,9 +1277,10 @@ After the tab is created, the hooks in (select-window (minibuffer-selected-window))) (let ((ignore-window-parameters t)) (delete-other-windows)) - ;; Create a new window to get rid of old window parameters - ;; (e.g. prev/next buffers) of old window. - (split-window) (delete-window) + (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)) (let ((buffer (if (functionp tab-bar-new-tab-choice) (funcall tab-bar-new-tab-choice) -- 2.39.5