From 7a99e7466ee84177ef61597e0c884c7e93312df5 Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Wed, 3 Apr 2024 20:42:11 +0300 Subject: [PATCH] Simplify tab-line-switch-to-prev-tab and tab-line-switch-to-next-tab. * 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 | 47 +++++++++++++++++++---------------------------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/lisp/tab-line.el b/lisp/tab-line.el index cc60f94c9c5..8c59f7b2e6d 100644 --- a/lisp/tab-line.el +++ b/lisp/tab-line.el @@ -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))))))) -- 2.39.5