From 82ecae035cbbf40963456c5dfcaa429d6da8987a Mon Sep 17 00:00:00 2001 From: Howard Abrams Date: Tue, 2 Dec 2025 17:13:16 -0800 Subject: [PATCH] Create tab-bar key sequences for first 10 tabs --- ha-config.org | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ha-config.org b/ha-config.org index 70132f8..f86ff5f 100644 --- a/ha-config.org +++ b/ha-config.org @@ -1048,13 +1048,13 @@ And some shortcut keys from the =general= project: I want to quickly jump, by the number shown on the tab, to that grouping. The following two functions create leader sequences with the name of the tab group: #+BEGIN_SRC emacs-lisp - (defun ha-tab-bar-update-names () + (defun ha-tab-bar-update-names (&optional changed-tab) "Create normal-mode keybindings for the tab groupings. This creates `SPC TAB 1' to jump to the first tab, etc." (interactive) ;; Remove all previously created keybindings: (ignore-errors - (dolist (indx (number-sequence 1 9)) + (dolist (indx (number-sequence 0 9)) (general-nmap :prefix "SPC" (format " %d" indx) nil))) ;; Loop through the existing tabs, create keys for each: @@ -1063,11 +1063,14 @@ I want to quickly jump, by the number shown on the tab, to that grouping. The fo (defun ha-tab-bar-update-tab-keybinding (tab-deets indx) "Create a keybinding to jump to tab described by TAB-DEETS. The key sequence, `SPC' `TAB' then INDX." - (let ((name (alist-get 'name tab-deets))) - (general-nmap :prefix "SPC" - (format " %d" (1+ indx)) - `(,name . - (lambda () (interactive) (tab-bar-select-tab ,(1+ indx))))))) + (when (< indx 10) + (let ((name (alist-get 'name tab-deets))) + (general-nmap :prefix "SPC" + ;; As indx is starts with 0, we need to create keybindings to + ;; match the tab labels by incrementing it by one ... unless, + ;; we are at 10, where we use 0 instead: + (format " %d" (if (= indx 9) 0 (1+ indx))) + `(,name . (lambda () (interactive) (tab-bar-select-tab ,(1+ indx)))))))) #+END_SRC Any time I create or delete a new tab, we can call =ha-tab-bar-update-names=: