Skip to content

Commit e70ce2d

Browse files
committed
Add auto hide tabs feature to tabs layer
Ideally it would be great to implement tabs switch with C-tab (or C-}) that shows the tabs as long as C is pressed. However Emacs does not support key release events so this function uses a timer as a workaround. To me Emacs looks better when tabs are hidden, and also packages like pdf-continuous-scroll-mode break when tabs are shown.
1 parent 47d02ba commit e70ce2d

File tree

5 files changed

+102
-38
lines changed

5 files changed

+102
-38
lines changed

CHANGELOG.develop

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ sane way, here is the complete list of changed key bindings
329329
- Move major specific error key bindings to ~SPC m E~ prefix
330330
(thanks to Sylvain Benner)
331331
- Changed ~SPC e e~ to ~SPC e b~ for =flycheck-buffer=
332+
***** Tabs
333+
- Add auto hide tabs feature (thanks to Daniel Nicolai)
332334
***** Vagrant
333335
- Key bindings:
334336
- Vagrant key bindings prefix is now ~SPC a V~.
@@ -390,6 +392,7 @@ sane way, here is the complete list of changed key bindings
390392
- prolog (thanks to Newres Al Haider)
391393
- reasonml (thanks to fredyr and Dave Aitken)
392394
- solidity (thanks to Brooklyn Zelenka and Seong Yong-ju)
395+
- tabs (thanks to Deepu Puthrote)
393396
- protobuf (thanks to Amol Mandhane)
394397
- restructuredtext (thanks to Wei-Wei Guo and Kalle Lindqvist)
395398
- semantic-web (thanks to Andreas Textor)

layers/+emacs/tabs/README.org

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This layer adds support for tabs. Implementation is done using [[https://github.
1414

1515
** Features:
1616
- Sets up tabs using Centaur tabs as backend
17+
- Optionally auto hide tabs after delay
1718

1819
* Install
1920
To use this configuration layer, add it to your =~/.spacemacs=. You will need to
@@ -24,6 +25,15 @@ file.
2425
You can set hooks for buffers in which it isn't desired to have tabs by
2526
customizing =centaur-tabs-hide-tabs-hooks=
2627

28+
Alternatively you can set ~tabs-auto-hide~ to ~t~ to auto hide tabs after some
29+
delay ~tabs-auto-hide-delay~ via the :variables keyword in your dotfile:
30+
#+begin_src emacs-lisp
31+
(tabs :variables
32+
tabs-auto-hide t
33+
tabs-auto-hide-delay 3)
34+
#+end_src
35+
36+
2737
* Key bindings
2838

2939
| Key binding | Description |

layers/+emacs/tabs/config.el

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
;;
1010
;;; License: GPLv3
1111

12-
(defvar tabs-navigation nil
12+
(defvaralias 'tabs-navigation 'centaur-tabs-cycle-scope
1313
"*Specify the scope of cyclic navigation through tabs.
1414
The following scopes are possible:
1515
@@ -20,38 +20,44 @@ The following scopes are possible:
2020
- nil
2121
Navigate through visible tabs, then through tab groups.")
2222

23-
(defvar tabs-gray-out-unselected nil
24-
"When non nil, enable gray icons for unselected buffer.")
23+
(defvaralias 'tabs-gray-out-unselected 'centaur-tabs-gray-out-icons)
2524

26-
(defvar tabs-height 22
27-
"The height of tab")
25+
(defvaralias 'tabs-height 'centaur-tabs-height)
2826

29-
(defvar tabs-show-icons t
30-
"When non nil, show icon from all-the-icons")
27+
(defvaralias 'tabs-show-icons 'centaur-tabs-set-icons)
3128

32-
(defvar tabs-set-modified-marker t
33-
"When non nil, display a marker when buffer is modified")
29+
(defvaralias 'tabs-set-modified-marker 'centaur-tabs-set-modified-marker)
3430

35-
(defvar tabs-modified-marker ""
36-
"Display appearance of modified marker if enabled")
31+
(defvaralias 'tabs-modified-marker 'centaur-tabs-modified-marker)
3732

38-
(defvar tabs-show-navigation-buttons nil
39-
"When non-nil, show buttons for backward/forward tabs")
33+
(defvaralias 'tabs-show-navigation-buttons 'centaur-tabs-show-navigation-buttons)
4034

41-
(defvar tabs-style "bar"
42-
"Style of tab; available values are \"bar\", \"alternate\", \"box\", \"chamfer\", \"rounded\", \"slant\", \"wave\", \"zigzag\" ")
35+
(defvaralias 'tabs-style 'centaur-tabs-style
36+
"Style of tab.
37+
Available values are \"bar\", \"alternate\", \"box\",
38+
\"chamfer\", \"rounded\", \"slant\", \"wave\", \"zigzag\" ")
4339

44-
(defvar tabs-group-by-project t
45-
"When non-nil, group tabs by projectile project. Default t.
46-
If non-nil calls (centaur-tabs-group-by-projectile-project)
47-
Otherwise calls (centaur-tabs-group-buffer-groups)")
40+
(defvaralias 'tabs-set-bar 'centaur-tabs-set-bar)
4841

49-
(defvar tabs-headline-match t
50-
"When non-nil, make headline use centaur-tabs-default-face. Default t. Calls (centaur-tabs-headline-match)")
42+
(defcustom tabs-group-by-project t
43+
"When non-nil, group tabs by projectile project.
44+
Default t. If non-nil calls (tabs-group-by-projectile-project)
45+
Otherwise calls (tabs-group-buffer-groups)"
46+
:type '(boolean)
47+
:group 'tabs)
5148

52-
(defvar tabs-set-bar 'left
53-
"When non-nil, display a bar to show currently selected tab.
54-
There are three options:
55-
- 'left: displays the bar at the left of the currently selected tab.
56-
- 'under: displays the bar under the currently selected tab.
57-
- 'over: displays the bar over the currently selected tab.")
49+
(defcustom tabs-headline-match t
50+
"When non-nil, make headline use tabs-default-face. Default t.
51+
Calls (tabs-headline-match)"
52+
:type '(boolean)
53+
:group 'tabs)
54+
55+
(defcustom tabs-auto-hide nil
56+
"If non-nil hide tabs automatically after TABS-AUTO-HIDE-DELAY seconds."
57+
:type '(boolean)
58+
:group 'tabs)
59+
60+
(defcustom tabs-auto-hide-delay 2
61+
"Tabs auto hide delay in seconds."
62+
:type '(float)
63+
:group 'tabs)

layers/+emacs/tabs/funcs.el

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
(defun spacemacs//tabs-timer-initialize (secs)
2+
(setq spacemacs-tabs-timer (run-with-timer secs nil (lambda () (centaur-tabs-local-mode 1)))))
3+
4+
(defun spacemacs//tabs-timer-hide ()
5+
(spacemacs//tabs-timer-initialize tabs-auto-hide-delay))
6+
7+
(defun spacemacs//tabs-switch-and-hide (arg)
8+
(cancel-timer spacemacs-tabs-timer)
9+
(centaur-tabs-local-mode 1)
10+
;; (if arg
11+
;; (centaur-tabs-backward)
12+
;; (centaur-tabs-forward))
13+
(pcase arg
14+
('backward (centaur-tabs-backward))
15+
('forward (centaur-tabs-forward))
16+
('backward-group (centaur-tabs-backward-group))
17+
('forward-group (centaur-tabs-forward-group)))
18+
(centaur-tabs-local-mode 0)
19+
(spacemacs//tabs-timer-hide))
20+
21+
(defun spacemacs//centaur-tabs-forward-and-hide ()
22+
(spacemacs//tabs-switch-and-hide 'forward))
23+
24+
(defun spacemacs//centaur-tabs-backward-and-hide ()
25+
(spacemacs//tabs-switch-and-hide 'backward))
26+
27+
(defun spacemacs/tabs-forward ()
28+
(interactive)
29+
(if tabs-auto-hide
30+
(spacemacs//centaur-tabs-forward-and-hide)
31+
(centaur-tabs-forward)))
32+
33+
(defun spacemacs/tabs-backward ()
34+
(interactive)
35+
(if tabs-auto-hide
36+
(spacemacs//centaur-tabs-backward-and-hide)
37+
(centaur-tabs-backward)))
38+
39+
(defun spacemacs/tabs-forward-group-and-hide ()
40+
(interactive)
41+
(spacemacs//tabs-switch-and-hide 'forward-group))
42+
43+
(defun spacemacs/tabs-backward-group-and-hide ()
44+
(interactive)
45+
(spacemacs//tabs-switch-and-hide 'backward-group))

layers/+emacs/tabs/packages.el

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@
1616
(use-package centaur-tabs
1717
:demand
1818
:config
19-
(setq centaur-tabs-cycle-scope tabs-navigation
20-
centaur-tabs-gray-out-icons tabs-gray-out-unselected
21-
centaur-tabs-height tabs-height
22-
centaur-tabs-modified-marker tabs-modified-marker
23-
centaur-tabs-set-bar tabs-set-bar
24-
centaur-tabs-set-icons tabs-show-icons
25-
centaur-tabs-set-modified-marker tabs-set-modified-marker
26-
centaur-tabs-show-navigation-buttons t
27-
centaur-tabs-style tabs-style)
19+
(setq tabs-show-icons t
20+
tabs-set-modified-marker t
21+
tabs-modified-marker ""
22+
tabs-set-bar 'left)
2823
(when tabs-headline-match
2924
(centaur-tabs-headline-match))
3025
(if tabs-group-by-project
3126
(centaur-tabs-group-by-projectile-project)
3227
(centaur-tabs-group-buffer-groups))
3328
(centaur-tabs-mode t)
29+
30+
(when tabs-auto-hide
31+
(add-hook 'window-setup-hook 'spacemacs//tabs-timer-hide)
32+
(add-hook 'find-file-hook 'spacemacs//tabs-timer-hide)
33+
(add-hook 'change-major-mode-hook 'spacemacs//tabs-timer-hide))
3434
:bind
35-
("C-{" . centaur-tabs-backward)
36-
("C-}" . centaur-tabs-forward)
35+
("C-{" . spacemacs/tabs-backward)
36+
("C-}" . spacemacs/tabs-forward)
3737
("C-M-{" . centaur-tabs-move-current-tab-to-left)
3838
("C-M-}" . centaur-tabs-move-current-tab-to-right)
3939
("C-c t s" . centaur-tabs-counsel-switch-group)

0 commit comments

Comments
 (0)