]> git.eshelyaron.com Git - emacs.git/commitdiff
Simplify tab-line-switch-to-prev-tab and tab-line-switch-to-next-tab.
authorJuri Linkov <juri@linkov.net>
Wed, 3 Apr 2024 17:42:11 +0000 (20:42 +0300)
committerEshel Yaron <me@eshelyaron.com>
Thu, 4 Apr 2024 11:40:22 +0000 (13:40 +0200)
* lisp/tab-line.el (tab-line-switch-to-prev-tab)
(tab-line-switch-to-next-tab): Use buffers instead of tabs.

(cherry picked from commit 7a41de3d515077e3895fe9201d7786134c82ca26)

lisp/tab-line.el

index cc60f94c9c52a583cf49e3410c34272e390ecb74..8c59f7b2e6d640a7d43bf93082b40aae44d303dc 100644 (file)
@@ -853,20 +853,15 @@ Its effect is the same as using the `previous-buffer' command
     (if (eq tab-line-tabs-function #'tab-line-tabs-window-buffers)
         (switch-to-prev-buffer window)
       (with-selected-window (or window (selected-window))
-        (let* ((tabs (seq-filter
-                      (lambda (tab) (or (bufferp tab) (assq 'buffer tab)))
-                      (funcall tab-line-tabs-function)))
-               (pos (seq-position
-                     tabs (current-buffer)
-                     (lambda (tab buffer)
-                       (if (bufferp tab)
-                           (eq buffer tab)
-                         (eq buffer (cdr (assq 'buffer tab)))))))
-               (tab (if pos
-                        (if (and tab-line-switch-cycling (<= pos 0))
-                            (nth (1- (length tabs)) tabs)
-                          (nth (1- pos) tabs))))
-               (buffer (if (bufferp tab) tab (cdr (assq 'buffer tab)))))
+        (let* ((buffers (seq-keep
+                         (lambda (tab) (or (and (bufferp tab) tab)
+                                           (alist-get 'buffer tab)))
+                         (funcall tab-line-tabs-function)))
+               (pos (seq-position buffers (current-buffer)))
+               (buffer (when pos
+                         (if (and tab-line-switch-cycling (<= pos 0))
+                             (nth (1- (length buffers)) buffers)
+                           (nth (1- pos) buffers)))))
           (when (bufferp buffer)
             (switch-to-buffer buffer)))))))
 
@@ -879,20 +874,16 @@ Its effect is the same as using the `next-buffer' command
     (if (eq tab-line-tabs-function #'tab-line-tabs-window-buffers)
         (switch-to-next-buffer window)
       (with-selected-window (or window (selected-window))
-        (let* ((tabs (seq-filter
-                      (lambda (tab) (or (bufferp tab) (assq 'buffer tab)))
-                      (funcall tab-line-tabs-function)))
-               (pos (seq-position
-                     tabs (current-buffer)
-                     (lambda (tab buffer)
-                       (if (bufferp tab)
-                           (eq buffer tab)
-                         (eq buffer (cdr (assq 'buffer tab)))))))
-               (tab (if pos
-                        (if (and tab-line-switch-cycling (<= (length tabs) (1+ pos)))
-                            (car tabs)
-                          (nth (1+ pos) tabs))))
-               (buffer (if (bufferp tab) tab (cdr (assq 'buffer tab)))))
+        (let* ((buffers (seq-keep
+                         (lambda (tab) (or (and (bufferp tab) tab)
+                                           (alist-get 'buffer tab)))
+                         (funcall tab-line-tabs-function)))
+               (pos (seq-position buffers (current-buffer)))
+               (buffer (when pos
+                         (if (and tab-line-switch-cycling
+                                  (<= (length buffers) (1+ pos)))
+                             (car buffers)
+                           (nth (1+ pos) buffers)))))
           (when (bufferp buffer)
             (switch-to-buffer buffer)))))))