summaryrefslogtreecommitdiff
path: root/lisp/tab-bar.el
diff options
context:
space:
mode:
authorJuri Linkov <juri@linkov.net>2019-10-23 23:58:30 +0300
committerJuri Linkov <juri@linkov.net>2019-10-23 23:58:30 +0300
commit96afd74bf852ca9405ffda5d9d281bb43d0c7f04 (patch)
tree86a08880f271143211010f77792c05d541fa17a8 /lisp/tab-bar.el
parent9f52f61be501534c53aada7ffb47c3f1fa6cf98b (diff)
downloademacs-96afd74bf852ca9405ffda5d9d281bb43d0c7f04.tar.gz
emacs-96afd74bf852ca9405ffda5d9d281bb43d0c7f04.tar.bz2
emacs-96afd74bf852ca9405ffda5d9d281bb43d0c7f04.zip
* 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.
Diffstat (limited to 'lisp/tab-bar.el')
-rw-r--r--lisp/tab-bar.el32
1 files changed, 24 insertions, 8 deletions
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index 8a4ad03d1d1..617057cf460 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)