bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#51935: 29.0.50; tab-switch hides identically named tabs


From: Juri Linkov
Subject: bug#51935: 29.0.50; tab-switch hides identically named tabs
Date: Sat, 20 Nov 2021 21:42:12 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu)

>> But the problem is that 'C-x t RET' is used mostly when the tab-bar
>> is disabled and not visible, so tabs are not positional in this case.
>
> But there still is the underlying order used by C-TAB/S-C-TAB, isn't it?

C-TAB/S-C-TAB keys are enabled only when tab-bar-mode is enabled.

> Depending on the configured completion framework C-x t RET will show
> candidates in order or not, but the interpretation of the suffix as a
> position seems relatively clear to me even in the unordered case, if
> not anything else at least it's an indication that there are
> additional tabs with the same name.

This could be implemented like below.  But it still messes the
text properties of the selected completion candidate,
even with using minibuffer-allow-text-properties,
so something is broken in the default completion framework.

diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index 1a1d0b1ea5..0590b5fe7c 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -1198,13 +1198,24 @@ tab-bar-switch-to-tab
 to get the name of the most recently visited tab, the second
 most recent, and so on."
   (interactive
-   (let* ((recent-tabs (mapcar (lambda (tab)
-                                 (alist-get 'name tab))
-                               (tab-bar--tabs-recent))))
+   (let* ((names '()) (i 1)
+          (recent-tabs
+           (mapcar (lambda (tab)
+                     (let ((name (alist-get 'name tab)))
+                       (if (member name names)
+                           (setq name (format "%s<%s>" name i))
+                         (setq name (copy-sequence name))
+                         (push name names))
+                       (setq i (1+ i))
+                       (propertize name 'tab tab)))
+                   (tab-bar--tabs-recent)))
+          (minibuffer-allow-text-properties t))
      (list (completing-read (format-prompt "Switch to tab by name"
                                            (car recent-tabs))
                             recent-tabs nil nil nil nil recent-tabs))))
-  (tab-bar-select-tab (1+ (or (tab-bar--tab-index-by-name name) 0))))
+  (let ((tab (get-text-property 0 'tab name)))
+    (tab-bar-select-tab (1+ (or (and tab (tab-bar--tab-index tab))
+                                (tab-bar--tab-index-by-name name) 0)))))
 
 (defalias 'tab-bar-select-tab-by-name 'tab-bar-switch-to-tab)
 
-- 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]