diff options
| author | shipmints | 2025-01-29 13:43:04 -0500 |
|---|---|---|
| committer | Juri Linkov | 2025-01-30 20:33:17 +0200 |
| commit | 6c46e2a363195fea338bc89cdc8fa9a46b63e63a (patch) | |
| tree | eaff140f0ddb02d004a69ac1ab1c871b9c41ca04 | |
| parent | 815c4dc0e07cfae5398c6145a4b4887b7fa64f42 (diff) | |
| download | emacs-6c46e2a363195fea338bc89cdc8fa9a46b63e63a.tar.gz emacs-6c46e2a363195fea338bc89cdc8fa9a46b63e63a.zip | |
Add new user option tab-bar-define-keys
* lisp/tab-bar.el (tab-bar-define-keys):
Add new defcustom tab-bar-define-keys. Reorganize key binding functions
to accommodate. Also remove checks for tab-bar-mode enabled in
'tab-bar-select-tab-modifiers', as unnecessary and which prevented user
changes from being accepted in cases where the user defers enabling
tab-bar-mode (bug#75918).
| -rw-r--r-- | etc/NEWS | 11 | ||||
| -rw-r--r-- | lisp/tab-bar.el | 68 |
2 files changed, 58 insertions, 21 deletions
| @@ -245,6 +245,17 @@ This hook allows you to operate on a reopened tab. | |||
| 245 | This is useful when you define custom tab parameters that may need | 245 | This is useful when you define custom tab parameters that may need |
| 246 | adjustment when a tab is restored, and avoids advice. | 246 | adjustment when a tab is restored, and avoids advice. |
| 247 | 247 | ||
| 248 | --- | ||
| 249 | *** New user option 'tab-bar-define-keys'. | ||
| 250 | This controls which key bindings tab-bar creates. Values are t, the | ||
| 251 | default, which defines all keys and is backwards compatible, 'numeric' | ||
| 252 | (tab number selection only), 'tab' (TAB and SHIFT-TAB keys only), nil | ||
| 253 | (which defines none). | ||
| 254 | |||
| 255 | This is useful to avoid key binding conflicts, such as when folding in | ||
| 256 | outline mode using TAB keys, or when a user wants to define her own | ||
| 257 | tab-bar keys without first having to remove the defaults. | ||
| 258 | |||
| 248 | ** Project | 259 | ** Project |
| 249 | 260 | ||
| 250 | --- | 261 | --- |
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el index f220ee768ae..85b8e3da1bf 100644 --- a/lisp/tab-bar.el +++ b/lisp/tab-bar.el | |||
| @@ -86,6 +86,35 @@ | |||
| 86 | :group 'tab-bar-faces) | 86 | :group 'tab-bar-faces) |
| 87 | 87 | ||
| 88 | 88 | ||
| 89 | |||
| 90 | (defvar tab-bar-mode-map (make-sparse-keymap) | ||
| 91 | "Tab Bar mode map.") | ||
| 92 | |||
| 93 | (defcustom tab-bar-define-keys t | ||
| 94 | "Define specified tab-bar key bindings. | ||
| 95 | If t, the default, all key mappings are defined. | ||
| 96 | |||
| 97 | If \\='numeric, define only numeric select-tab key mappings, and in | ||
| 98 | conjunction with `tab-bar-select-tab-modifiers', which see. | ||
| 99 | |||
| 100 | If \\='tab, define only TAB and SHIFT-TAB tab-selection key mappings. | ||
| 101 | |||
| 102 | If nil, do not define any key mappings. | ||
| 103 | |||
| 104 | Customize this option, or use `setopt' to ensure it will take effect." | ||
| 105 | :type '(choice (const :tag "All keys" t) | ||
| 106 | (const :tag "Numeric tab selection keys" numeric) | ||
| 107 | (const :tag "TAB and SHIFT-TAB selection keys" tab) | ||
| 108 | (const :tag "None" nil)) | ||
| 109 | :initialize #'custom-initialize-default | ||
| 110 | :set (lambda (sym val) | ||
| 111 | (tab-bar--undefine-keys) | ||
| 112 | (set-default sym val) | ||
| 113 | ;; Enable the new keybindings | ||
| 114 | (tab-bar--define-keys)) | ||
| 115 | :group 'tab-bar | ||
| 116 | :version "31.1") | ||
| 117 | |||
| 89 | (defcustom tab-bar-select-tab-modifiers '() | 118 | (defcustom tab-bar-select-tab-modifiers '() |
| 90 | "List of modifier keys for selecting tab-bar tabs by their numbers. | 119 | "List of modifier keys for selecting tab-bar tabs by their numbers. |
| 91 | Possible modifier keys are `control', `meta', `shift', `hyper', `super' and | 120 | Possible modifier keys are `control', `meta', `shift', `hyper', `super' and |
| @@ -104,18 +133,17 @@ For easier selection of tabs by their numbers, consider customizing | |||
| 104 | (const alt)) | 133 | (const alt)) |
| 105 | :initialize #'custom-initialize-default | 134 | :initialize #'custom-initialize-default |
| 106 | :set (lambda (sym val) | 135 | :set (lambda (sym val) |
| 107 | (when tab-bar-mode | 136 | (tab-bar--undefine-keys) |
| 108 | (tab-bar--undefine-keys)) | ||
| 109 | (set-default sym val) | 137 | (set-default sym val) |
| 110 | ;; Reenable the tab-bar with new keybindings | 138 | ;; Enable the new keybindings |
| 111 | (when tab-bar-mode | 139 | (tab-bar--define-keys)) |
| 112 | (tab-bar--define-keys))) | ||
| 113 | :group 'tab-bar | 140 | :group 'tab-bar |
| 114 | :version "27.1") | 141 | :version "27.1") |
| 115 | 142 | ||
| 116 | (defun tab-bar--define-keys () | 143 | (defun tab-bar--define-keys () |
| 117 | "Install key bindings to switch between tabs if so configured." | 144 | "Install key bindings to switch between tabs if so configured." |
| 118 | (when tab-bar-select-tab-modifiers | 145 | (when (and (memq tab-bar-define-keys '(t numeric)) |
| 146 | tab-bar-select-tab-modifiers) | ||
| 119 | (define-key tab-bar-mode-map | 147 | (define-key tab-bar-mode-map |
| 120 | (vector (append tab-bar-select-tab-modifiers (list ?0))) | 148 | (vector (append tab-bar-select-tab-modifiers (list ?0))) |
| 121 | #'tab-recent) | 149 | #'tab-recent) |
| @@ -128,6 +156,14 @@ For easier selection of tabs by their numbers, consider customizing | |||
| 128 | (vector (append tab-bar-select-tab-modifiers (list ?9))) | 156 | (vector (append tab-bar-select-tab-modifiers (list ?9))) |
| 129 | #'tab-last)) | 157 | #'tab-last)) |
| 130 | 158 | ||
| 159 | (when (memq tab-bar-define-keys '(t tab)) | ||
| 160 | (unless (global-key-binding [(control tab)]) | ||
| 161 | (define-key tab-bar-mode-map [(control tab)] #'tab-next)) | ||
| 162 | (unless (global-key-binding [(control shift tab)]) | ||
| 163 | (define-key tab-bar-mode-map [(control shift tab)] #'tab-previous)) | ||
| 164 | (unless (global-key-binding [(control shift iso-lefttab)]) | ||
| 165 | (define-key tab-bar-mode-map [(control shift iso-lefttab)] #'tab-previous))) | ||
| 166 | |||
| 131 | ;; Replace default value with a condition that supports displaying | 167 | ;; Replace default value with a condition that supports displaying |
| 132 | ;; global-mode-string in the tab bar instead of the mode line. | 168 | ;; global-mode-string in the tab bar instead of the mode line. |
| 133 | (when (and (memq 'tab-bar-format-global tab-bar-format) | 169 | (when (and (memq 'tab-bar-format-global tab-bar-format) |
| @@ -152,7 +188,11 @@ For easier selection of tabs by their numbers, consider customizing | |||
| 152 | nil t)) | 188 | nil t)) |
| 153 | (define-key tab-bar-mode-map | 189 | (define-key tab-bar-mode-map |
| 154 | (vector (append tab-bar-select-tab-modifiers (list ?9))) | 190 | (vector (append tab-bar-select-tab-modifiers (list ?9))) |
| 155 | nil t))) | 191 | nil t)) |
| 192 | |||
| 193 | (define-key tab-bar-mode-map [(control tab)] nil t) | ||
| 194 | (define-key tab-bar-mode-map [(control shift tab)] nil t) | ||
| 195 | (define-key tab-bar-mode-map [(control shift iso-lefttab)] nil t)) | ||
| 156 | 196 | ||
| 157 | (defun tab-bar--load-buttons () | 197 | (defun tab-bar--load-buttons () |
| 158 | "Load the icons for the tab buttons." | 198 | "Load the icons for the tab buttons." |
| @@ -242,20 +282,6 @@ a list of frames to update." | |||
| 242 | (if (and tab-bar-mode (eq tab-bar-show t)) 1 0)) | 282 | (if (and tab-bar-mode (eq tab-bar-show t)) 1 0)) |
| 243 | (assq-delete-all 'tab-bar-lines default-frame-alist))))) | 283 | (assq-delete-all 'tab-bar-lines default-frame-alist))))) |
| 244 | 284 | ||
| 245 | (defun tab-bar-mode--tab-key-bind (map key binding) | ||
| 246 | ;; Don't override user customized global key bindings | ||
| 247 | (define-key map key | ||
| 248 | `(menu-item "" ,binding | ||
| 249 | :filter ,(lambda (cmd) (unless (global-key-binding key) cmd))))) | ||
| 250 | |||
| 251 | (defvar tab-bar-mode-map | ||
| 252 | (let ((map (make-sparse-keymap))) | ||
| 253 | (tab-bar-mode--tab-key-bind map [(control tab)] #'tab-next) | ||
| 254 | (tab-bar-mode--tab-key-bind map [(control shift tab)] #'tab-previous) | ||
| 255 | (tab-bar-mode--tab-key-bind map [(control shift iso-lefttab)] #'tab-previous) | ||
| 256 | map) | ||
| 257 | "Tab Bar mode map.") | ||
| 258 | |||
| 259 | (define-minor-mode tab-bar-mode | 285 | (define-minor-mode tab-bar-mode |
| 260 | "Toggle the tab bar in all graphical frames (Tab Bar mode). | 286 | "Toggle the tab bar in all graphical frames (Tab Bar mode). |
| 261 | 287 | ||