diff options
| author | Juri Linkov | 2025-08-31 21:23:05 +0300 |
|---|---|---|
| committer | Juri Linkov | 2025-08-31 21:23:05 +0300 |
| commit | 1ba75cc6fc57e27c489d49f9fba0f7d6788e030b (patch) | |
| tree | ec7958693742f4325789e3eb062d2f961d9eb03c | |
| parent | 07adb8b59dee772b56612b90acd19e1a5a456628 (diff) | |
| download | emacs-1ba75cc6fc57e27c489d49f9fba0f7d6788e030b.tar.gz emacs-1ba75cc6fc57e27c489d49f9fba0f7d6788e030b.zip | |
New user option 'tab-line-define-keys'
* lisp/tab-line.el (tab-line-define-keys): New defcustom.
(tab-line--define-keys, tab-line--undefine-keys):
New functions that explicitly bind commands from
'tab-line-mode-map' to 'ctl-x-map'.
(tab-line-mode-map): Leave this keymap empty by default
to avoid breaking 'ctl-x-map' (bug#79323).
(global-tab-line-mode): Call either 'tab-line--define-keys'
or 'tab-line--undefine-keys'.
| -rw-r--r-- | etc/NEWS | 6 | ||||
| -rw-r--r-- | lisp/tab-line.el | 59 |
2 files changed, 57 insertions, 8 deletions
| @@ -435,6 +435,12 @@ When non-nil, it truncates the tab bar, and therefore prevents | |||
| 435 | wrapping and resizing the tab bar to more than one line. | 435 | wrapping and resizing the tab bar to more than one line. |
| 436 | 436 | ||
| 437 | --- | 437 | --- |
| 438 | *** New user option 'tab-line-define-keys'. | ||
| 439 | When t, the default, it redefines window buffer switching keys | ||
| 440 | such as 'C-x <left>' and 'C-x <right>' to tab-line specific variants | ||
| 441 | for switching tabs. | ||
| 442 | |||
| 443 | --- | ||
| 438 | *** New command 'tab-line-move-tab-forward' ('C-x M-<right>'). | 444 | *** New command 'tab-line-move-tab-forward' ('C-x M-<right>'). |
| 439 | Together with the new command 'tab-line-move-tab-backward' | 445 | Together with the new command 'tab-line-move-tab-backward' |
| 440 | ('C-x M-<left>'), it can be used to move the current tab | 446 | ('C-x M-<left>'), it can be used to move the current tab |
diff --git a/lisp/tab-line.el b/lisp/tab-line.el index 7caae8bc2c1..fbf7f79eda8 100644 --- a/lisp/tab-line.el +++ b/lisp/tab-line.el | |||
| @@ -1277,14 +1277,54 @@ However, return the correct mouse position list if EVENT is a | |||
| 1277 | (event-start event))) | 1277 | (event-start event))) |
| 1278 | 1278 | ||
| 1279 | 1279 | ||
| 1280 | (defcustom tab-line-define-keys t | ||
| 1281 | "Define specific tab-line key bindings. | ||
| 1282 | If t, the default, key mappings for switching and moving tabs | ||
| 1283 | are defined. If nil, do not define any key mappings." | ||
| 1284 | :type 'boolean | ||
| 1285 | :initialize #'custom-initialize-default | ||
| 1286 | :set (lambda (sym val) | ||
| 1287 | (tab-line--undefine-keys) | ||
| 1288 | (set-default sym val) | ||
| 1289 | ;; Enable the new keybindings | ||
| 1290 | (tab-line--define-keys)) | ||
| 1291 | :group 'tab-line | ||
| 1292 | :version "31.1") | ||
| 1293 | |||
| 1294 | (defun tab-line--define-keys () | ||
| 1295 | "Install key bindings to switch between tabs if so configured." | ||
| 1296 | (when tab-line-define-keys | ||
| 1297 | (when (eq (keymap-lookup ctl-x-map "<left>") 'previous-buffer) | ||
| 1298 | (keymap-set ctl-x-map "<left>" #'tab-line-switch-to-prev-tab)) | ||
| 1299 | (when (eq (keymap-lookup ctl-x-map "C-<left>") 'previous-buffer) | ||
| 1300 | (keymap-set ctl-x-map "C-<left>" #'tab-line-switch-to-prev-tab)) | ||
| 1301 | (unless (keymap-lookup ctl-x-map "M-<left>") | ||
| 1302 | (keymap-set ctl-x-map "M-<left>" #'tab-line-move-tab-backward)) | ||
| 1303 | (when (eq (keymap-lookup ctl-x-map "<right>") 'next-buffer) | ||
| 1304 | (keymap-set ctl-x-map "<right>" #'tab-line-switch-to-next-tab)) | ||
| 1305 | (when (eq (keymap-lookup ctl-x-map "C-<right>") 'next-buffer) | ||
| 1306 | (keymap-set ctl-x-map "C-<right>" #'tab-line-switch-to-next-tab)) | ||
| 1307 | (unless (keymap-lookup ctl-x-map "M-<right>") | ||
| 1308 | (keymap-set ctl-x-map "M-<right>" #'tab-line-move-tab-forward)))) | ||
| 1309 | |||
| 1310 | (defun tab-line--undefine-keys () | ||
| 1311 | "Uninstall key bindings previously bound by `tab-line--define-keys'." | ||
| 1312 | (when tab-line-define-keys | ||
| 1313 | (when (eq (keymap-lookup ctl-x-map "<left>") 'tab-line-switch-to-prev-tab) | ||
| 1314 | (keymap-set ctl-x-map "<left>" #'previous-buffer)) | ||
| 1315 | (when (eq (keymap-lookup ctl-x-map "C-<left>") 'tab-line-switch-to-prev-tab) | ||
| 1316 | (keymap-set ctl-x-map "C-<left>" #'previous-buffer)) | ||
| 1317 | (when (eq (keymap-lookup ctl-x-map "M-<left>") 'tab-line-move-tab-backward) | ||
| 1318 | (keymap-set ctl-x-map "M-<left>" nil)) | ||
| 1319 | (when (eq (keymap-lookup ctl-x-map "<right>") 'tab-line-switch-to-next-tab) | ||
| 1320 | (keymap-set ctl-x-map "<right>" #'next-buffer)) | ||
| 1321 | (when (eq (keymap-lookup ctl-x-map "C-<right>") 'tab-line-switch-to-next-tab) | ||
| 1322 | (keymap-set ctl-x-map "C-<right>" #'next-buffer)) | ||
| 1323 | (when (eq (keymap-lookup ctl-x-map "M-<right>") 'tab-line-move-tab-forward) | ||
| 1324 | (keymap-set ctl-x-map "M-<right>" nil)))) | ||
| 1325 | |||
| 1280 | (defvar-keymap tab-line-mode-map | 1326 | (defvar-keymap tab-line-mode-map |
| 1281 | :doc "Keymap for keys of `tab-line-mode'." | 1327 | :doc "Keymap for keys of `tab-line-mode'.") |
| 1282 | "C-x <left>" #'tab-line-switch-to-prev-tab | ||
| 1283 | "C-x C-<left>" #'tab-line-switch-to-prev-tab | ||
| 1284 | "C-x M-<left>" #'tab-line-move-tab-backward | ||
| 1285 | "C-x <right>" #'tab-line-switch-to-next-tab | ||
| 1286 | "C-x C-<right>" #'tab-line-switch-to-next-tab | ||
| 1287 | "C-x M-<right>" #'tab-line-move-tab-forward) | ||
| 1288 | 1328 | ||
| 1289 | (defvar-keymap tab-line-switch-repeat-map | 1329 | (defvar-keymap tab-line-switch-repeat-map |
| 1290 | :doc "Keymap to repeat tab/buffer cycling. Used in `repeat-mode'." | 1330 | :doc "Keymap to repeat tab/buffer cycling. Used in `repeat-mode'." |
| @@ -1374,7 +1414,10 @@ of `tab-line-exclude', are exempt from `tab-line-mode'." | |||
| 1374 | (define-globalized-minor-mode global-tab-line-mode | 1414 | (define-globalized-minor-mode global-tab-line-mode |
| 1375 | tab-line-mode tab-line-mode--turn-on | 1415 | tab-line-mode tab-line-mode--turn-on |
| 1376 | :group 'tab-line | 1416 | :group 'tab-line |
| 1377 | :version "27.1") | 1417 | :version "27.1" |
| 1418 | (if global-tab-line-mode | ||
| 1419 | (tab-line--define-keys) | ||
| 1420 | (tab-line--undefine-keys))) | ||
| 1378 | 1421 | ||
| 1379 | 1422 | ||
| 1380 | (global-set-key [tab-line down-mouse-3] 'tab-line-context-menu) | 1423 | (global-set-key [tab-line down-mouse-3] 'tab-line-context-menu) |