diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el index a36be13e37..340f012247 100644 --- a/lisp/tab-bar.el +++ b/lisp/tab-bar.el @@ -645,6 +645,33 @@ tab-bar-move-tab (to-index (mod (+ from-index arg) (length tabs)))) (tab-bar-move-tab-to (1+ to-index) (1+ from-index)))) +(defun tab-bar-move-tab-to-frame (arg &optional from-frame from-index to-frame to-index) + "Move tab from FROM-INDEX position to new position at TO-INDEX. +FROM-INDEX defaults to the current tab index. +FROM-INDEX and TO-INDEX count from 1. +FROM-FRAME specifies the source frame and defaults to the selected frame. +TO-FRAME specifies the target frame and defaults the next frame. +Interactively, ARG selects the ARGth different frame to move to." + (interactive "P") + (unless from-frame + (setq from-frame (selected-frame))) + (unless to-frame + (dotimes (_ (prefix-numeric-value arg)) + (setq to-frame (next-frame to-frame)))) + (unless (eq from-frame to-frame) + (let* ((from-tabs (with-selected-frame from-frame + (funcall tab-bar-tabs-function))) + (from-index (or from-index (1+ (tab-bar--current-tab-index from-tabs)))) + (from-tab (nth (1- from-index) from-tabs)) + (to-tabs (with-selected-frame to-frame + (funcall tab-bar-tabs-function))) + (to-index (max 0 (min (1- (or to-index 1)) (1- (length to-tabs)))))) + (setq from-tabs (delq from-tab from-tabs)) + (cl-pushnew (assq-delete-all 'wc from-tab) (nthcdr to-index to-tabs)) + (set-frame-parameter from-frame 'tabs from-tabs) + (set-frame-parameter to-frame 'tabs to-tabs) + (force-mode-line-update t)))) + (defcustom tab-bar-new-tab-to 'right "Defines where to create a new tab.