aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/emacs-lisp/seq.el2
-rw-r--r--lisp/tab-bar.el32
2 files changed, 30 insertions, 4 deletions
diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el
index 8d4093004a7..918b0dcd390 100644
--- a/lisp/emacs-lisp/seq.el
+++ b/lisp/emacs-lisp/seq.el
@@ -237,6 +237,7 @@ The result is a sequence of the same type as SEQUENCE."
237(cl-defmethod seq-sort (pred (list list)) 237(cl-defmethod seq-sort (pred (list list))
238 (sort (seq-copy list) pred)) 238 (sort (seq-copy list) pred))
239 239
240;;;###autoload
240(defun seq-sort-by (function pred sequence) 241(defun seq-sort-by (function pred sequence)
241 "Sort SEQUENCE using PRED as a comparison function. 242 "Sort SEQUENCE using PRED as a comparison function.
242Elements of SEQUENCE are transformed by FUNCTION before being 243Elements of SEQUENCE are transformed by FUNCTION before being
@@ -295,6 +296,7 @@ list."
295 exclude)) 296 exclude))
296 sequence)))) 297 sequence))))
297 298
299;;;###autoload
298(cl-defgeneric seq-remove (pred sequence) 300(cl-defgeneric seq-remove (pred sequence)
299 "Return a list of all the elements for which (PRED element) is nil in SEQUENCE." 301 "Return a list of all the elements for which (PRED element) is nil in SEQUENCE."
300 (seq-filter (lambda (elt) (not (funcall pred elt))) 302 (seq-filter (lambda (elt) (not (funcall pred elt)))
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index f7b0f261139..2b71bf8b2c5 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -458,6 +458,16 @@ Return its existing value or a new value."
458 (seq-position (or tabs (funcall tab-bar-tabs-function)) 458 (seq-position (or tabs (funcall tab-bar-tabs-function))
459 name (lambda (a b) (equal (cdr (assq 'name a)) b)))) 459 name (lambda (a b) (equal (cdr (assq 'name a)) b))))
460 460
461(defun tab-bar--tab-index-recent (nth &optional tabs)
462 (let* ((tabs (or tabs (funcall tab-bar-tabs-function)))
463 (sorted-tabs
464 (seq-sort-by (lambda (tab) (cdr (assq 'time tab))) #'>
465 (seq-remove (lambda (tab)
466 (eq (car tab) 'current-tab))
467 tabs)))
468 (tab (nth (1- nth) sorted-tabs)))
469 (tab-bar--tab-index tab tabs)))
470
461 471
462(defun tab-bar-select-tab (&optional arg) 472(defun tab-bar-select-tab (&optional arg)
463 "Switch to the tab by its absolute position ARG in the tab bar. 473 "Switch to the tab by its absolute position ARG in the tab bar.
@@ -514,6 +524,16 @@ to the numeric argument. ARG counts from 1."
514 (setq arg 1)) 524 (setq arg 1))
515 (tab-bar-switch-to-next-tab (- arg))) 525 (tab-bar-switch-to-next-tab (- arg)))
516 526
527(defun tab-bar-switch-to-recent-tab (&optional arg)
528 "Switch to ARGth most recently visited tab."
529 (interactive "p")
530 (unless (integerp arg)
531 (setq arg 1))
532 (let ((tab-index (tab-bar--tab-index-recent arg)))
533 (if tab-index
534 (tab-bar-select-tab (1+ tab-index))
535 (message "No more recent tabs"))))
536
517(defun tab-bar-switch-to-tab (name) 537(defun tab-bar-switch-to-tab (name)
518 "Switch to the tab by NAME." 538 "Switch to the tab by NAME."
519 (interactive (list (completing-read "Switch to tab by name: " 539 (interactive (list (completing-read "Switch to tab by name: "
@@ -626,12 +646,14 @@ If ARG is zero, create a new tab in place of the current tab."
626(defvar tab-bar-closed-tabs nil 646(defvar tab-bar-closed-tabs nil
627 "A list of closed tabs to be able to undo their closing.") 647 "A list of closed tabs to be able to undo their closing.")
628 648
629(defcustom tab-bar-close-tab-select 'right 649(defcustom tab-bar-close-tab-select 'recent
630 "Defines what tab to select after closing the specified tab. 650 "Defines what tab to select after closing the specified tab.
631If `left', select the adjacent left tab. 651If `left', select the adjacent left tab.
632If `right', select the adjacent right tab." 652If `right', select the adjacent right tab.
653If `recent', select the most recently visited tab."
633 :type '(choice (const :tag "Select left tab" left) 654 :type '(choice (const :tag "Select left tab" left)
634 (const :tag "Select right tab" right)) 655 (const :tag "Select right tab" right)
656 (const :tag "Select recent tab" recent))
635 :group 'tab-bar 657 :group 'tab-bar
636 :version "27.1") 658 :version "27.1")
637 659
@@ -682,7 +704,8 @@ TO-INDEX counts from 1."
682 ('left (1- current-index)) 704 ('left (1- current-index))
683 ('right (if (> (length tabs) (1+ current-index)) 705 ('right (if (> (length tabs) (1+ current-index))
684 (1+ current-index) 706 (1+ current-index)
685 (1- current-index))))))) 707 (1- current-index)))
708 ('recent (tab-bar--tab-index-recent 1 tabs))))))
686 (setq to-index (max 0 (min (or to-index 0) (1- (length tabs))))) 709 (setq to-index (max 0 (min (or to-index 0) (1- (length tabs)))))
687 (tab-bar-select-tab (1+ to-index)) 710 (tab-bar-select-tab (1+ to-index))
688 ;; Re-read tabs after selecting another tab 711 ;; Re-read tabs after selecting another tab
@@ -819,6 +842,7 @@ function `tab-bar-tab-name-function'."
819(defalias 'tab-select 'tab-bar-select-tab) 842(defalias 'tab-select 'tab-bar-select-tab)
820(defalias 'tab-next 'tab-bar-switch-to-next-tab) 843(defalias 'tab-next 'tab-bar-switch-to-next-tab)
821(defalias 'tab-previous 'tab-bar-switch-to-prev-tab) 844(defalias 'tab-previous 'tab-bar-switch-to-prev-tab)
845(defalias 'tab-recent 'tab-bar-switch-to-recent-tab)
822(defalias 'tab-move 'tab-bar-move-tab) 846(defalias 'tab-move 'tab-bar-move-tab)
823(defalias 'tab-move-to 'tab-bar-move-tab-to) 847(defalias 'tab-move-to 'tab-bar-move-tab-to)
824(defalias 'tab-rename 'tab-bar-rename-tab) 848(defalias 'tab-rename 'tab-bar-rename-tab)