From 56a7c60872272eef2dbd4fd071d0af0441f374d8 Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Tue, 15 Oct 2019 23:38:18 +0300 Subject: [PATCH] * lisp/tab-bar.el (tab-bar-select-tab-modifiers): New defcustom. (tab-bar-mode): Use tab-bar-select-tab-modifiers to bind tab-bar-select-tab. Don't override user customized key bindings of C-TAB, C-S-TAB. On disabling tab-bar-mode, unset only keys bound by tab-bar. --- lisp/tab-bar.el | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el index 13829efe94c..f9d4de4ebf2 100644 --- a/lisp/tab-bar.el +++ b/lisp/tab-bar.el @@ -83,6 +83,27 @@ :version "27.1" :group 'tab-bar-faces) + +(defcustom tab-bar-select-tab-modifiers '() + "List of key modifiers for selecting a tab by its index digit. +Possible modifiers are `control', `meta', `shift', `hyper', `super' and +`alt'." + :type '(set :tag "Tab selection key modifiers" + (const control) + (const meta) + (const shift) + (const hyper) + (const super) + (const alt)) + :initialize 'custom-initialize-default + :set (lambda (sym val) + (set-default sym val) + ;; Reenable the tab-bar with new keybindings + (tab-bar-mode -1) + (tab-bar-mode 1)) + :group 'tab-bar + :version "27.1") + (define-minor-mode tab-bar-mode "Toggle the tab bar in all graphical frames (Tab Bar mode)." @@ -118,10 +139,27 @@ :ascent center)) tab-bar-close-button)) - (when tab-bar-mode - (global-set-key [(control shift iso-lefttab)] 'tab-previous) - (global-set-key [(control shift tab)] 'tab-previous) - (global-set-key [(control tab)] 'tab-next))) + (if tab-bar-mode + (progn + (when tab-bar-select-tab-modifiers + (dotimes (i 9) + (global-set-key (vector (append tab-bar-select-tab-modifiers + (list (+ i 1 ?0)))) + 'tab-bar-select-tab))) + ;; Don't override user customized key bindings + (unless (global-key-binding [(control tab)]) + (global-set-key [(control tab)] 'tab-next)) + (unless (global-key-binding [(control shift tab)]) + (global-set-key [(control shift tab)] 'tab-previous)) + (unless (global-key-binding [(control shift iso-lefttab)]) + (global-set-key [(control shift iso-lefttab)] 'tab-previous))) + ;; Unset only keys bound by tab-bar + (when (eq (global-key-binding [(control tab)]) 'tab-next) + (global-unset-key [(control tab)])) + (when (eq (global-key-binding [(control shift tab)]) 'tab-previous) + (global-unset-key [(control shift tab)])) + (when (eq (global-key-binding [(control shift iso-lefttab)]) 'tab-previous) + (global-unset-key [(control shift iso-lefttab)])))) (defun tab-bar-handle-mouse (event) "Text-mode emulation of switching tabs on the tab bar. -- 2.39.5