]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/tab-bar.el: (tab-bar-detach-tab) New command
authorAdam Porter <adam@alphapapa.net>
Wed, 29 Sep 2021 19:37:38 +0000 (22:37 +0300)
committerJuri Linkov <juri@linkov.net>
Wed, 29 Sep 2021 19:37:38 +0000 (22:37 +0300)
(tab-bar-detach-tab): New command.
(tab-bar-mouse-context-menu): Add menu entry.

With thanks to Matt Beshara <m@mfa.pw> for his feedback.
https://lists.gnu.org/archive/html/emacs-devel/2021-09/msg02141.html

lisp/tab-bar.el

index abf0e814c417cf5b2e63f20377d751e9817e286d..9f64e2d1eebca11974646d249ee58073ed50dd1e 100644 (file)
@@ -312,6 +312,11 @@ that closes only when clicked on the close button."
                                   (tab-bar-duplicate-tab
                                    nil ,tab-number))
                     :help "Duplicate the tab"))
+      (define-key-after menu [detach-tab]
+        `(menu-item "Detach" (lambda () (interactive)
+                               (tab-bar-detach-tab
+                                ,tab-number))
+                    :help "Detach the tab to new frame"))
       (define-key-after menu [close]
         `(menu-item "Close" (lambda () (interactive)
                               (tab-bar-close-tab ,tab-number))
@@ -1201,6 +1206,17 @@ Interactively, ARG selects the ARGth different frame to move to."
       (tab-bar-tabs-set to-tabs to-frame)
       (force-mode-line-update t))))
 
+(defun tab-bar-detach-tab (&optional from-number)
+  "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))
+         (new-frame (make-frame `((name . ,tab-name)))))
+    (tab-bar-move-tab-to-frame nil nil from-number new-frame nil)
+    (with-selected-frame new-frame
+      (tab-bar-close-tab))))
+
 \f
 (defcustom tab-bar-new-tab-to 'right
   "Defines where to create a new tab.