emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 96afd74: * lisp/tab-bar.el: Allow to specify intera


From: Juri Linkov
Subject: [Emacs-diffs] master 96afd74: * lisp/tab-bar.el: Allow to specify interactively where to add a new tab.
Date: Wed, 23 Oct 2019 16:58:37 -0400 (EDT)

branch: master
commit 96afd74bf852ca9405ffda5d9d281bb43d0c7f04
Author: Juri Linkov <address@hidden>
Commit: Juri Linkov <address@hidden>

    * lisp/tab-bar.el: Allow to specify interactively where to add a new tab.
    
    * lisp/tab-bar.el (tab-bar-new-tab-to): Rename from tab-bar-new-tab.
    Add optional arg TO-INDEX.
    (tab-bar-new-tab): New implementation to use relative ARG.
    (tab-new-to): Alias to tab-bar-new-tab-to.
---
 lisp/tab-bar.el | 32 ++++++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 8 deletions(-)

diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index 8a4ad03..617057c 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -561,9 +561,11 @@ If `rightmost', create as the last tab."
   :group 'tab-bar
   :version "27.1")
 
-(defun tab-bar-new-tab ()
-  "Add a new tab at the position specified by `tab-bar-new-tab-to'."
-  (interactive)
+(defun tab-bar-new-tab-to (&optional to-index)
+  "Add a new tab at the absolute position TO-INDEX.
+TO-INDEX counts from 1.  If no TO-INDEX is specified, then add
+a new tab at the position specified by `tab-bar-new-tab-to'."
+  (interactive "P")
   (let* ((tabs (funcall tab-bar-tabs-function))
          (from-index (tab-bar--current-tab-index tabs))
          (from-tab (tab-bar--tab)))
@@ -585,11 +587,12 @@ If `rightmost', create as the last tab."
     (when from-index
       (setf (nth from-index tabs) from-tab))
     (let ((to-tab (tab-bar--current-tab))
-          (to-index (pcase tab-bar-new-tab-to
-                      ('leftmost 0)
-                      ('rightmost (length tabs))
-                      ('left (1- (or from-index 1)))
-                      ('right (1+ (or from-index 0))))))
+          (to-index (or (if to-index (1- to-index))
+                        (pcase tab-bar-new-tab-to
+                          ('leftmost 0)
+                          ('rightmost (length tabs))
+                          ('left (1- (or from-index 1)))
+                          ('right (1+ (or from-index 0)))))))
       (setq to-index (max 0 (min (or to-index 0) (length tabs))))
       (cl-pushnew to-tab (nthcdr to-index tabs))
       (when (eq to-index 0)
@@ -606,6 +609,18 @@ If `rightmost', create as the last tab."
     (unless tab-bar-mode
       (message "Added new tab at %s" tab-bar-new-tab-to))))
 
+(defun tab-bar-new-tab (&optional arg)
+  "Create a new tab ARG positions to the right.
+If a negative ARG, create a new tab ARG positions to the left.
+If ARG is zero, create a new tab in place of the current tab."
+  (interactive "P")
+  (if arg
+      (let* ((tabs (funcall tab-bar-tabs-function))
+             (from-index (or (tab-bar--current-tab-index tabs) 0))
+             (to-index (+ from-index (prefix-numeric-value arg))))
+        (tab-bar-new-tab-to (1+ to-index)))
+    (tab-bar-new-tab-to)))
+
 
 (defvar tab-bar-closed-tabs nil
   "A list of closed tabs to be able to undo their closing.")
@@ -771,6 +786,7 @@ function `tab-bar-tab-name-function'."
 ;;; Short aliases
 
 (defalias 'tab-new         'tab-bar-new-tab)
+(defalias 'tab-new-to      'tab-bar-new-tab-to)
 (defalias 'tab-close       'tab-bar-close-tab)
 (defalias 'tab-close-other 'tab-bar-close-other-tabs)
 (defalias 'tab-undo        'tab-bar-undo-close-tab)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]