Skip to content

Commit f0e1bf5

Browse files
committed
Fix bugs in tab-bar and tab-line and mention remaining features in manual.
* doc/emacs/frames.texi (Tab Bars): Mention tab-bar-new-tab-to, tab-bar-close-last-tab-choice, tab-bar-close-tab-select, tab-undo, tab-select, tab-bar-history-mode. * doc/emacs/windows.texi (Tab Line): Mention tab-line-tabs-function. * lisp/tab-bar.el (tab-bar-select-tab-modifiers): Mention tab-bar-tab-hints in docstring. (tab-bar-tab-hints): Mention tab-bar-select-tab-modifiers in docstring. (tab-bar-select-tab): Mention tab-bar-select-tab-modifiers in docstring. (tab-bar-switch-to-tab): Expand the docstring. (tab-bar-new-tab-to): Fix bug in handling 'left' value. (tab-bar-close-tab): Fix bug in handling 'left' value. (tab-bar-undo-close-tab): Use funcall tab-bar-tabs-function instead of direct call to tab-bar-tabs. (tab-bar-history-back, tab-bar-history-forward): Add docstrings. (tab-bar-history-mode): Expand docstring. * lisp/tab-line.el (tab-line-format): Fix bug for handling window switching that should set face 'tab-line-tab-current'.
1 parent f0b9f18 commit f0e1bf5

File tree

4 files changed

+94
-19
lines changed

4 files changed

+94
-19
lines changed

doc/emacs/frames.texi

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,7 @@ Note that the Tab Bar is different from the Tab Line (@pxref{Tab Line}).
12661266
Whereas tabs on the Tab Line at the top of each window are used to
12671267
switch between buffers, tabs on the Tab Bar at the top of each frame
12681268
are used to switch between window configurations containing several
1269-
windows.
1269+
windows with buffers.
12701270

12711271
@findex tab-bar-mode
12721272
To toggle the use of tab bars, type @kbd{M-x tab-bar-mode}. This
@@ -1324,21 +1324,34 @@ current before calling the command that adds a new tab.
13241324
To start a new tab with other buffers, customize the variable
13251325
@code{tab-bar-new-tab-choice}.
13261326

1327+
@vindex tab-bar-new-tab-to
1328+
The variable @code{tab-bar-new-tab-to} defines where to place a new tab.
1329+
By default, a new tab is added on the right side of the current tab.
1330+
13271331
The following commands can be used to delete tabs:
13281332

13291333
@table @kbd
13301334
@item C-x t 0
13311335
@kindex C-x t 0
13321336
@findex tab-close
13331337
Close the selected tab (@code{tab-close}). It has no effect if there
1334-
is only one tab.
1338+
is only one tab, unless the variable @code{tab-bar-close-last-tab-choice}
1339+
is customized to a non-default value.
13351340

13361341
@item C-x t 1
13371342
@kindex C-x t 1
13381343
@findex tab-close-other
13391344
Close all tabs on the selected frame, except the selected one.
13401345
@end table
13411346

1347+
@vindex tab-bar-close-tab-select
1348+
The variable @code{tab-bar-close-tab-select} defines what tab to
1349+
select after closing the current tab. By default, it selects
1350+
a recently used tab.
1351+
1352+
@findex tab-undo
1353+
The command @code{tab-undo} restores the last closed tab.
1354+
13421355
The following commands can be used to switch between tabs:
13431356

13441357
@table @kbd
@@ -1358,22 +1371,60 @@ switches back to the previous Nth tab.
13581371
Switch to the previous tab. With a positive numeric argument N, it
13591372
switches to the previous Nth tab; with a negative argument −N, it
13601373
switches back to the next Nth tab.
1374+
1375+
@item C-x t @key{RET} @var{tabname} @key{RET}
1376+
Switch to the tab by its name, with completion on all tab names.
1377+
Default values are tab names sorted by recency, so you can use
1378+
@kbd{M-n} (@code{next-history-element}) to get the name of the last
1379+
visited tab, the second last, and so on.
1380+
1381+
@item @var{modifier}-@var{tabnumber}
1382+
@findex tab-select
1383+
Switch to the tab by its number. After customizing the variable
1384+
@code{tab-bar-select-tab-modifiers} to specify a @var{modifier} key, you
1385+
can select a tab by its ordinal number using the specified modifier in
1386+
combination with the tab number to select. To display the tab number
1387+
alongside the tab name, you can customize another variable
1388+
@code{tab-bar-tab-hints}. This will help you to decide what key to press
1389+
to select the tab by its number.
1390+
1391+
@item @var{modifier}-@kbd{0}
1392+
@findex tab-recent
1393+
Switch to the recent tab. The key combination is the modifier key
1394+
defined by @code{tab-bar-select-tab-modifiers} and the key @kbd{0}.
1395+
With a numeric argument N, switch to the Nth recent tab.
13611396
@end table
13621397

13631398
The following commands can be used to operate on tabs:
13641399

13651400
@table @kbd
13661401
@item C-x t r @var{tabname} @key{RET}
1402+
@findex tab-rename
13671403
Rename the current tab to @var{tabname}. You can control the
13681404
programmatic name given to a tab by default by customizing the
13691405
variable @code{tab-bar-tab-name-function}.
13701406

13711407
@item C-x t m
1408+
@findex tab-move
13721409
Move the current tab N positions to the right with a positive numeric
1373-
argument N. With a negative argument −N, it moves the current tab
1410+
argument N. With a negative argument −N, move the current tab
13741411
N positions to the left.
13751412
@end table
13761413

1414+
@findex tab-bar-history-mode
1415+
You can enable @code{tab-bar-history-mode} to remember window
1416+
configurations used in every tab, and restore them.
1417+
1418+
@table @kbd
1419+
@item tab-bar-history-back
1420+
Restore a previous window configuration used in the current tab.
1421+
This navigates back in the history of window configurations.
1422+
1423+
@item tab-bar-history-forward
1424+
Cancel restoration of the previous window configuration.
1425+
This navigates forward in the history of window configurations.
1426+
@end table
1427+
13771428
@node Dialog Boxes
13781429
@section Using Dialog Boxes
13791430
@cindex dialog boxes

doc/emacs/windows.texi

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,16 @@ Selecting the previous window-local tab is the same as typing @kbd{C-x
628628
same as @kbd{C-x @key{RIGHT}} (@code{next-buffer}). Both commands
629629
support a numeric prefix argument as a repeat count.
630630

631+
You can customize the variable @code{tab-line-tabs-function} to define
632+
the preferred contents of the tab line. By default, it displays all
633+
buffers previously visited in the window, as described above. But you
634+
can also set it to display a list of buffers with the same major mode
635+
as the current buffer, or to display buffers grouped by their major
636+
mode, where clicking on the mode name in the first tab displays a list
637+
of all major modes where you can select another group of buffers.
638+
631639
Note that the Tab Line is different from the Tab Bar (@pxref{Tab Bars}).
632640
Whereas tabs on the Tab Bar at the top of each frame are used to
633-
switch between window configurations containing several windows,
641+
switch between window configurations containing several windows with buffers,
634642
tabs on the Tab Line at the top of each window are used to switch
635-
between buffers.
643+
between buffers in the window.

lisp/tab-bar.el

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@
8787

8888

8989
(defcustom tab-bar-select-tab-modifiers '()
90-
"List of key modifiers for selecting a tab by its index digit.
91-
Possible modifiers are `control', `meta', `shift', `hyper', `super' and
92-
`alt'."
93-
:type '(set :tag "Tab selection key modifiers"
90+
"List of modifier keys for selecting a tab by its index digit.
91+
Possible modifier keys are `control', `meta', `shift', `hyper', `super' and
92+
`alt'. To help you to select a tab by its number, you can customize
93+
`tab-bar-tab-hints' that will show tab numbers alongside the tab name."
94+
:type '(set :tag "Tab selection modifier keys"
9495
(const control)
9596
(const meta)
9697
(const shift)
@@ -310,7 +311,8 @@ If nil, don't show it at all."
310311

311312
(defcustom tab-bar-tab-hints nil
312313
"Show absolute numbers on tabs in the tab bar before the tab name.
313-
This helps to select the tab by its number using `tab-bar-select-tab'."
314+
This helps to select the tab by its number using `tab-bar-select-tab'
315+
and `tab-bar-select-tab-modifiers'."
314316
:type 'boolean
315317
:initialize 'custom-initialize-default
316318
:set (lambda (sym val)
@@ -563,9 +565,10 @@ Return its existing value or a new value."
563565

564566
(defun tab-bar-select-tab (&optional arg)
565567
"Switch to the tab by its absolute position ARG in the tab bar.
566-
When this command is bound to a numeric key (with a prefix or modifier),
567-
calling it without an argument will translate its bound numeric key
568-
to the numeric argument. ARG counts from 1."
568+
When this command is bound to a numeric key (with a prefix or modifier key
569+
using `tab-bar-select-tab-modifiers'), calling it without an argument
570+
will translate its bound numeric key to the numeric argument.
571+
ARG counts from 1."
569572
(interactive "P")
570573
(unless (integerp arg)
571574
(let ((key (event-basic-type last-command-event)))
@@ -664,7 +667,10 @@ to the numeric argument. ARG counts from 1."
664667
(message "No more recent tabs"))))
665668

666669
(defun tab-bar-switch-to-tab (name)
667-
"Switch to the tab by NAME."
670+
"Switch to the tab by NAME.
671+
Default values are tab names sorted by recency, so you can use \
672+
\\<minibuffer-local-map>\\[next-history-element]
673+
to get the name of the last visited tab, the second last, and so on."
668674
(interactive
669675
(let* ((recent-tabs (mapcar (lambda (tab)
670676
(alist-get 'name tab))
@@ -789,7 +795,7 @@ After the tab is created, the hooks in
789795
(pcase tab-bar-new-tab-to
790796
('leftmost 0)
791797
('rightmost (length tabs))
792-
('left (1- (or from-index 1)))
798+
('left (or from-index 1))
793799
('right (1+ (or from-index 0)))
794800
((pred functionp)
795801
(funcall tab-bar-new-tab-to))))))
@@ -920,7 +926,7 @@ for the last tab on a frame is determined by
920926
;; Select another tab before deleting the current tab
921927
(let ((to-index (or (if to-index (1- to-index))
922928
(pcase tab-bar-close-tab-select
923-
('left (1- current-index))
929+
('left (1- (if (< current-index 1) 2 current-index)))
924930
('right (if (> (length tabs) (1+ current-index))
925931
(1+ current-index)
926932
(1- current-index)))
@@ -1004,7 +1010,7 @@ for the last tab on a frame is determined by
10041010
(unless (eq frame (selected-frame))
10051011
(select-frame-set-input-focus frame))
10061012

1007-
(let ((tabs (tab-bar-tabs)))
1013+
(let ((tabs (funcall tab-bar-tabs-function)))
10081014
(setq index (max 0 (min index (length tabs))))
10091015
(cl-pushnew tab (nthcdr index tabs))
10101016
(when (eq index 0)
@@ -1102,6 +1108,8 @@ function `tab-bar-tab-name-function'."
11021108
(setq tab-bar-history-omit nil)))
11031109

11041110
(defun tab-bar-history-back ()
1111+
"Restore a previous window configuration used in the current tab.
1112+
This navigates back in the history of window configurations."
11051113
(interactive)
11061114
(setq tab-bar-history-omit t)
11071115
(let* ((history (pop (gethash (selected-frame) tab-bar-history-back)))
@@ -1119,6 +1127,8 @@ function `tab-bar-tab-name-function'."
11191127
(message "No more tab back history"))))
11201128

11211129
(defun tab-bar-history-forward ()
1130+
"Cancel restoration of the previous window configuration.
1131+
This navigates forward in the history of window configurations."
11221132
(interactive)
11231133
(setq tab-bar-history-omit t)
11241134
(let* ((history (pop (gethash (selected-frame) tab-bar-history-forward)))
@@ -1136,7 +1146,9 @@ function `tab-bar-tab-name-function'."
11361146
(message "No more tab forward history"))))
11371147

11381148
(define-minor-mode tab-bar-history-mode
1139-
"Toggle tab history mode for the tab bar."
1149+
"Toggle tab history mode for the tab bar.
1150+
Tab history mode remembers window configurations used in every tab,
1151+
and can restore them."
11401152
:global t :group 'tab-bar
11411153
(if tab-bar-history-mode
11421154
(progn

lisp/tab-line.el

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,12 @@ variable `tab-line-tabs-function'."
474474
"Template for displaying tab line for selected window."
475475
(let* ((tabs (funcall tab-line-tabs-function))
476476
(cache-key (list tabs
477+
;; handle buffer renames
477478
(buffer-name (window-buffer))
478-
(window-parameter nil 'tab-line-hscroll)))
479+
;; handle tab-line scrolling
480+
(window-parameter nil 'tab-line-hscroll)
481+
;; for setting face 'tab-line-tab-current'
482+
(eq (selected-window) (old-selected-window))))
479483
(cache (window-parameter nil 'tab-line-cache)))
480484
;; Enable auto-hscroll again after it was disabled on manual scrolling.
481485
;; The moment to enable it is when the window-buffer was updated.

0 commit comments

Comments
 (0)