]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/tab-bar.el (tab-bar-select-tab-modifiers): New defcustom.
authorJuri Linkov <juri@linkov.net>
Tue, 15 Oct 2019 20:38:18 +0000 (23:38 +0300)
committerJuri Linkov <juri@linkov.net>
Tue, 15 Oct 2019 20:38:18 +0000 (23:38 +0300)
(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

index 13829efe94ce63666b54667a84135010c9dfb83f..f9d4de4ebf2d8c073a6ce89fcfe86974b158fc1f 100644 (file)
   :version "27.1"
   :group 'tab-bar-faces)
 
+\f
+(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")
+
 \f
 (define-minor-mode tab-bar-mode
   "Toggle the tab bar in all graphical frames (Tab Bar mode)."
                                           :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.