Skip to content

Commit 34cce90

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 34cce90

File tree

4 files changed

+75
-2
lines changed

4 files changed

+75
-2
lines changed

CHANGELOG.develop

+3
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

+10
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 ~spacemacs-tabs-auto-hide~ to ~t~ to auto hide tabs after some
29+
delay ~spacemacs-tabs-auto-hide-delay~ via the :variables keyword in your dotfile:
30+
#+begin_src emacs-lisp
31+
(tabs :variables
32+
spacemacs-tabs-auto-hide t
33+
spacemacs-tabs-auto-hide-delay 3)
34+
#+end_src
35+
36+
2737
* Key bindings
2838

2939
| Key binding | Description |

layers/+emacs/tabs/funcs.el

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
(defcustom spacemacs-tabs-auto-hide nil
2+
"If non-nil hide tabs automatically after TABS-AUTO-HIDE-DELAY seconds."
3+
:type '(boolean)
4+
:group 'centaur-tabs)
5+
6+
(defcustom spacemacs-tabs-auto-hide-delay 2
7+
"Tabs auto hide delay in seconds."
8+
:type '(float)
9+
:group 'centaur-tabs)
10+
11+
(defun spacemacs//tabs-timer-initialize (secs)
12+
(setq spacemacs-tabs-timer (run-with-timer secs nil (lambda () (centaur-tabs-local-mode 1)))))
13+
14+
(defun spacemacs//tabs-timer-hide ()
15+
(spacemacs//tabs-timer-initialize spacemacs-tabs-auto-hide-delay))
16+
17+
(when spacemacs-tabs-auto-hide
18+
(add-hook 'window-setup-hook 'spacemacs//tabs-timer-hide)
19+
(add-hook 'find-file-hook 'spacemacs//tabs-timer-hide)
20+
(add-hook 'change-major-mode-hook 'spacemacs//tabs-timer-hide))
21+
22+
(defun spacemacs//tabs-switch-and-hide (arg)
23+
(cancel-timer spacemacs-tabs-timer)
24+
(centaur-tabs-local-mode 1)
25+
;; (if arg
26+
;; (centaur-tabs-backward)
27+
;; (centaur-tabs-forward))
28+
(pcase arg
29+
('backward (centaur-tabs-backward))
30+
('forward (centaur-tabs-forward))
31+
('backward-group (centaur-tabs-backward-group))
32+
('forward-group (centaur-tabs-forward-group)))
33+
(centaur-tabs-local-mode 0)
34+
(spacemacs//tabs-timer-hide))
35+
36+
(defun spacemacs//centaur-tabs-forward-and-hide ()
37+
(spacemacs//tabs-switch-and-hide 'forward))
38+
39+
(defun spacemacs//centaur-tabs-backward-and-hide ()
40+
(spacemacs//tabs-switch-and-hide 'backward))
41+
42+
(defun spacemacs/tabs-forward ()
43+
(interactive)
44+
(if spacemacs-tabs-auto-hide
45+
(spacemacs//centaur-tabs-forward-and-hide)
46+
(centaur-tabs-forward)))
47+
48+
(defun spacemacs/tabs-backward ()
49+
(interactive)
50+
(if spacemacs-tabs-auto-hide
51+
(spacemacs//centaur-tabs-backward-and-hide)
52+
(centaur-tabs-backward)))
53+
54+
(defun spacemacs/tabs-forward-group-and-hide ()
55+
(interactive)
56+
(spacemacs//tabs-switch-and-hide 'forward-group))
57+
58+
(defun spacemacs/tabs-backward-group-and-hide ()
59+
(interactive)
60+
(spacemacs//tabs-switch-and-hide 'backward-group))

layers/+emacs/tabs/packages.el

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
(centaur-tabs-group-buffer-groups))
3333
(centaur-tabs-mode t)
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)