From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#69578: 30.0.50; tab-bar-mode binding of (control tab) not always useful Date: Mon, 11 Mar 2024 19:50:20 +0200 Organization: LINKOV.NET Message-ID: <86h6hcd5er.fsf@mail.linkov.net> References: <87y1aog83s.fsf@bernoul.li> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="922"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu) Cc: 69578@debbugs.gnu.org To: Jonas Bernoulli Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Mar 11 19:03:22 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rjjze-00006b-Cg for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 11 Mar 2024 19:03:22 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rjjyp-0005d6-Oh; Mon, 11 Mar 2024 14:02:31 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rjjyn-0005cm-CF for bug-gnu-emacs@gnu.org; Mon, 11 Mar 2024 14:02:29 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rjjyn-00033F-4W for bug-gnu-emacs@gnu.org; Mon, 11 Mar 2024 14:02:29 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rjjzJ-0000fS-NX for bug-gnu-emacs@gnu.org; Mon, 11 Mar 2024 14:03:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 11 Mar 2024 18:03:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69578 X-GNU-PR-Package: emacs Original-Received: via spool by 69578-submit@debbugs.gnu.org id=B69578.17101801672546 (code B ref 69578); Mon, 11 Mar 2024 18:03:01 +0000 Original-Received: (at 69578) by debbugs.gnu.org; 11 Mar 2024 18:02:47 +0000 Original-Received: from localhost ([127.0.0.1]:41216 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rjjz4-0000ez-DY for submit@debbugs.gnu.org; Mon, 11 Mar 2024 14:02:46 -0400 Original-Received: from relay5-d.mail.gandi.net ([217.70.183.197]:56651) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rjjz1-0000eg-FM for 69578@debbugs.gnu.org; Mon, 11 Mar 2024 14:02:44 -0400 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id 8BD851C0003; Mon, 11 Mar 2024 18:02:01 +0000 (UTC) In-Reply-To: <87y1aog83s.fsf@bernoul.li> (Jonas Bernoulli's message of "Mon, 11 Mar 2024 15:23:51 +0100") X-GND-Sasl: juri@linkov.net X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:281487 Archived-At: --=-=-= Content-Type: text/plain >> So, maybe these bindings should not be done? > > Too late for that now, but they should definitely be done in a way that > users can customize, without having to advice tab-bar--define-keys (and > tab-bar--undefine-keys). Thanks for bringing up this issue. Customization of keys was not supported since no once asked for it, I guess because tab-bar--define-keys respected the existing global keybindings before defining own. But indeed this doesn't work for local keymaps. > Maybe by using a mode map? If there is some reason this cannot be > done, then maybe a "dummy keymap" could be used? (User could then > manipulate the fake tab-bar-mode-map like any keymap, but the bindings > it contains would then somehow be "transplanted" into the global map > by tab-bar--define-keys.) Just adding a simple mode map completely makes it customizable since 'define-minor-mode' is able to pick it by naming convention: (defvar tab-bar-mode-map (let ((map (make-sparse-keymap))) (define-key map [(control tab)] #'tab-next) (define-key map [(control shift tab)] #'tab-previous) (define-key map [(control shift iso-lefttab)] #'tab-previous) map) "Tab Bar mode map.") The rest of complexity in the following patch comes from the need to address the customization of 'tab-bar-select-tab-modifiers'. There is a slight backward incompatibility for users who have own global keybindings for C-TAB. They will need to unbind these keys in the new map. Then this change should be announced in NEWS: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=tab-bar-mode-map.patch diff --git a/etc/NEWS b/etc/NEWS index 19cd170e5c7..0aab2d04ca2 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -285,6 +285,11 @@ selected or deselected at the end of executing the current command. ** Tab Bars and Tab Lines +--- +*** New keymap 'tab-bar-mode-map'. +If you have global keybinding for 'C-TAB', then you might want +to unbind the same keybinding in 'tab-bar-mode-map'. + --- *** New user option 'tab-bar-tab-name-format-functions'. It can be used to add, remove and reorder functions that change diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el index 61efa332e0b..07470f072e1 100644 --- a/lisp/tab-bar.el +++ b/lisp/tab-bar.el @@ -104,10 +104,11 @@ tab-bar-select-tab-modifiers (const alt)) :initialize #'custom-initialize-default :set (lambda (sym val) + (when tab-bar-mode + (tab-bar--undefine-keys)) (set-default sym val) ;; Reenable the tab-bar with new keybindings (when tab-bar-mode - (tab-bar--undefine-keys) (tab-bar--define-keys))) :group 'tab-bar :version "27.1") @@ -115,21 +116,17 @@ tab-bar-select-tab-modifiers (defun tab-bar--define-keys () "Install key bindings to switch between tabs if so configured." (when tab-bar-select-tab-modifiers - (global-set-key (vector (append tab-bar-select-tab-modifiers (list ?0))) - #'tab-recent) + (define-key tab-bar-mode-map + (vector (append tab-bar-select-tab-modifiers (list ?0))) + #'tab-recent) (dotimes (i 8) - (global-set-key (vector (append tab-bar-select-tab-modifiers - (list (+ i 1 ?0)))) - #'tab-bar-select-tab)) - (global-set-key (vector (append tab-bar-select-tab-modifiers (list ?9))) - #'tab-last)) - ;; 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)) + (define-key tab-bar-mode-map + (vector (append tab-bar-select-tab-modifiers + (list (+ i 1 ?0)))) + #'tab-bar-select-tab)) + (define-key tab-bar-mode-map + (vector (append tab-bar-select-tab-modifiers (list ?9))) + #'tab-last)) ;; Replace default value with a condition that supports displaying ;; global-mode-string in the tab bar instead of the mode line. @@ -144,12 +141,18 @@ tab-bar--define-keys (defun tab-bar--undefine-keys () "Uninstall key bindings previously bound by `tab-bar--define-keys'." - (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)]))) + (when tab-bar-select-tab-modifiers + (define-key tab-bar-mode-map + (vector (append tab-bar-select-tab-modifiers (list ?0))) + nil) + (dotimes (i 8) + (define-key tab-bar-mode-map + (vector (append tab-bar-select-tab-modifiers + (list (+ i 1 ?0)))) + nil)) + (define-key tab-bar-mode-map + (vector (append tab-bar-select-tab-modifiers (list ?9))) + nil))) (defun tab-bar--load-buttons () "Load the icons for the tab buttons." @@ -239,6 +242,14 @@ tab-bar--update-tab-bar-lines (if (and tab-bar-mode (eq tab-bar-show t)) 1 0)) (assq-delete-all 'tab-bar-lines default-frame-alist))))) +(defvar tab-bar-mode-map + (let ((map (make-sparse-keymap))) + (define-key map [(control tab)] #'tab-next) + (define-key map [(control shift tab)] #'tab-previous) + (define-key map [(control shift iso-lefttab)] #'tab-previous) + map) + "Tab Bar mode map.") + (define-minor-mode tab-bar-mode "Toggle the tab bar in all graphical frames (Tab Bar mode)." :global t --=-=-=--