From 5730742bdf996f0a780579068b33459a6e3139ef Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 26 Nov 2023 21:38:07 +0300 Subject: [PATCH] feat(tazjin/emacs): i3-style jumping back&forth for tab-bar-mode Change-Id: I19cab91646241edc38a58bf5546c9dd8161abeb0 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10130 Reviewed-by: tazjin Autosubmit: tazjin Tested-by: BuildkiteCI --- users/tazjin/emacs/config/desktop.el | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/users/tazjin/emacs/config/desktop.el b/users/tazjin/emacs/config/desktop.el index 2a1f0a8d4..2688588d2 100644 --- a/users/tazjin/emacs/config/desktop.el +++ b/users/tazjin/emacs/config/desktop.el @@ -119,8 +119,22 @@ ;; Tab-management shortcuts +(defun tab-bar-select-or-return () + "This function behaves like `tab-bar-select-tab', except it calls +`tab-recent' if asked to jump to the current tab. This simulates +the back&forth behaviour of i3." + (interactive) + (let* ((key (event-basic-type last-command-event)) + (tab (if (and (characterp key) (>= key ?1) (<= key ?9)) + (- key ?0) + 0)) + (current (1+ (tab-bar--current-tab-index)))) + (if (eq tab current) + (tab-recent) + (tab-bar-select-tab tab)))) + (dotimes (i 8) - (exwm-input-set-key (kbd (format "s-%d" (+ 1 i))) #'tab-bar-select-tab)) + (exwm-input-set-key (kbd (format "s-%d" (+ 1 i))) #'tab-bar-select-or-return)) (exwm-input-set-key (kbd "s-9") #'tab-last) (exwm-input-set-key (kbd "s-f") #'tab-next)