diff options
| author | Juri Linkov | 2019-10-23 23:58:30 +0300 |
|---|---|---|
| committer | Juri Linkov | 2019-10-23 23:58:30 +0300 |
| commit | 96afd74bf852ca9405ffda5d9d281bb43d0c7f04 (patch) | |
| tree | 86a08880f271143211010f77792c05d541fa17a8 | |
| parent | 9f52f61be501534c53aada7ffb47c3f1fa6cf98b (diff) | |
| download | emacs-96afd74bf852ca9405ffda5d9d281bb43d0c7f04.tar.gz 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.
| -rw-r--r-- | lisp/tab-bar.el | 32 |
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." | |||
| 561 | :group 'tab-bar | 561 | :group 'tab-bar |
| 562 | :version "27.1") | 562 | :version "27.1") |
| 563 | 563 | ||
| 564 | (defun tab-bar-new-tab () | 564 | (defun tab-bar-new-tab-to (&optional to-index) |
| 565 | "Add a new tab at the position specified by `tab-bar-new-tab-to'." | 565 | "Add a new tab at the absolute position TO-INDEX. |
| 566 | (interactive) | 566 | TO-INDEX counts from 1. If no TO-INDEX is specified, then add |
| 567 | a new tab at the position specified by `tab-bar-new-tab-to'." | ||
| 568 | (interactive "P") | ||
| 567 | (let* ((tabs (funcall tab-bar-tabs-function)) | 569 | (let* ((tabs (funcall tab-bar-tabs-function)) |
| 568 | (from-index (tab-bar--current-tab-index tabs)) | 570 | (from-index (tab-bar--current-tab-index tabs)) |
| 569 | (from-tab (tab-bar--tab))) | 571 | (from-tab (tab-bar--tab))) |
| @@ -585,11 +587,12 @@ If `rightmost', create as the last tab." | |||
| 585 | (when from-index | 587 | (when from-index |
| 586 | (setf (nth from-index tabs) from-tab)) | 588 | (setf (nth from-index tabs) from-tab)) |
| 587 | (let ((to-tab (tab-bar--current-tab)) | 589 | (let ((to-tab (tab-bar--current-tab)) |
| 588 | (to-index (pcase tab-bar-new-tab-to | 590 | (to-index (or (if to-index (1- to-index)) |
| 589 | ('leftmost 0) | 591 | (pcase tab-bar-new-tab-to |
| 590 | ('rightmost (length tabs)) | 592 | ('leftmost 0) |
| 591 | ('left (1- (or from-index 1))) | 593 | ('rightmost (length tabs)) |
| 592 | ('right (1+ (or from-index 0)))))) | 594 | ('left (1- (or from-index 1))) |
| 595 | ('right (1+ (or from-index 0))))))) | ||
| 593 | (setq to-index (max 0 (min (or to-index 0) (length tabs)))) | 596 | (setq to-index (max 0 (min (or to-index 0) (length tabs)))) |
| 594 | (cl-pushnew to-tab (nthcdr to-index tabs)) | 597 | (cl-pushnew to-tab (nthcdr to-index tabs)) |
| 595 | (when (eq to-index 0) | 598 | (when (eq to-index 0) |
| @@ -606,6 +609,18 @@ If `rightmost', create as the last tab." | |||
| 606 | (unless tab-bar-mode | 609 | (unless tab-bar-mode |
| 607 | (message "Added new tab at %s" tab-bar-new-tab-to)))) | 610 | (message "Added new tab at %s" tab-bar-new-tab-to)))) |
| 608 | 611 | ||
| 612 | (defun tab-bar-new-tab (&optional arg) | ||
| 613 | "Create a new tab ARG positions to the right. | ||
| 614 | If a negative ARG, create a new tab ARG positions to the left. | ||
| 615 | If ARG is zero, create a new tab in place of the current tab." | ||
| 616 | (interactive "P") | ||
| 617 | (if arg | ||
| 618 | (let* ((tabs (funcall tab-bar-tabs-function)) | ||
| 619 | (from-index (or (tab-bar--current-tab-index tabs) 0)) | ||
| 620 | (to-index (+ from-index (prefix-numeric-value arg)))) | ||
| 621 | (tab-bar-new-tab-to (1+ to-index))) | ||
| 622 | (tab-bar-new-tab-to))) | ||
| 623 | |||
| 609 | 624 | ||
| 610 | (defvar tab-bar-closed-tabs nil | 625 | (defvar tab-bar-closed-tabs nil |
| 611 | "A list of closed tabs to be able to undo their closing.") | 626 | "A list of closed tabs to be able to undo their closing.") |
| @@ -771,6 +786,7 @@ function `tab-bar-tab-name-function'." | |||
| 771 | ;;; Short aliases | 786 | ;;; Short aliases |
| 772 | 787 | ||
| 773 | (defalias 'tab-new 'tab-bar-new-tab) | 788 | (defalias 'tab-new 'tab-bar-new-tab) |
| 789 | (defalias 'tab-new-to 'tab-bar-new-tab-to) | ||
| 774 | (defalias 'tab-close 'tab-bar-close-tab) | 790 | (defalias 'tab-close 'tab-bar-close-tab) |
| 775 | (defalias 'tab-close-other 'tab-bar-close-other-tabs) | 791 | (defalias 'tab-close-other 'tab-bar-close-other-tabs) |
| 776 | (defalias 'tab-undo 'tab-bar-undo-close-tab) | 792 | (defalias 'tab-undo 'tab-bar-undo-close-tab) |