1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

* lisp/tab-bar.el (tab-bar-switch-to-recent-tab): New command.

(tab-recent): Alias to tab-bar-switch-to-recent-tab.
(tab-bar--tab-index-recent): New internal function.
(tab-bar-close-tab-select): Add new default option 'recent'.
(tab-bar-close-tab): Handle it.

* lisp/emacs-lisp/seq.el (seq-sort-by, seq-remove): Add autoload.
This commit is contained in:
Juri Linkov 2019-10-27 01:16:10 +03:00
parent 802dc5d4dc
commit 5a9a01797b
2 changed files with 30 additions and 4 deletions

View file

@ -237,6 +237,7 @@ The result is a sequence of the same type as SEQUENCE."
(cl-defmethod seq-sort (pred (list list))
(sort (seq-copy list) pred))
;;;###autoload
(defun seq-sort-by (function pred sequence)
"Sort SEQUENCE using PRED as a comparison function.
Elements of SEQUENCE are transformed by FUNCTION before being
@ -295,6 +296,7 @@ list."
exclude))
sequence))))
;;;###autoload
(cl-defgeneric seq-remove (pred sequence)
"Return a list of all the elements for which (PRED element) is nil in SEQUENCE."
(seq-filter (lambda (elt) (not (funcall pred elt)))

View file

@ -458,6 +458,16 @@ Return its existing value or a new value."
(seq-position (or tabs (funcall tab-bar-tabs-function))
name (lambda (a b) (equal (cdr (assq 'name a)) b))))
(defun tab-bar--tab-index-recent (nth &optional tabs)
(let* ((tabs (or tabs (funcall tab-bar-tabs-function)))
(sorted-tabs
(seq-sort-by (lambda (tab) (cdr (assq 'time tab))) #'>
(seq-remove (lambda (tab)
(eq (car tab) 'current-tab))
tabs)))
(tab (nth (1- nth) sorted-tabs)))
(tab-bar--tab-index tab tabs)))
(defun tab-bar-select-tab (&optional arg)
"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."
(setq arg 1))
(tab-bar-switch-to-next-tab (- arg)))
(defun tab-bar-switch-to-recent-tab (&optional arg)
"Switch to ARGth most recently visited tab."
(interactive "p")
(unless (integerp arg)
(setq arg 1))
(let ((tab-index (tab-bar--tab-index-recent arg)))
(if tab-index
(tab-bar-select-tab (1+ tab-index))
(message "No more recent tabs"))))
(defun tab-bar-switch-to-tab (name)
"Switch to the tab by NAME."
(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."
(defvar tab-bar-closed-tabs nil
"A list of closed tabs to be able to undo their closing.")
(defcustom tab-bar-close-tab-select 'right
(defcustom tab-bar-close-tab-select 'recent
"Defines what tab to select after closing the specified tab.
If `left', select the adjacent left tab.
If `right', select the adjacent right tab."
If `right', select the adjacent right tab.
If `recent', select the most recently visited tab."
:type '(choice (const :tag "Select left tab" left)
(const :tag "Select right tab" right))
(const :tag "Select right tab" right)
(const :tag "Select recent tab" recent))
:group 'tab-bar
:version "27.1")
@ -682,7 +704,8 @@ TO-INDEX counts from 1."
('left (1- current-index))
('right (if (> (length tabs) (1+ current-index))
(1+ current-index)
(1- current-index)))))))
(1- current-index)))
('recent (tab-bar--tab-index-recent 1 tabs))))))
(setq to-index (max 0 (min (or to-index 0) (1- (length tabs)))))
(tab-bar-select-tab (1+ to-index))
;; Re-read tabs after selecting another tab
@ -819,6 +842,7 @@ function `tab-bar-tab-name-function'."
(defalias 'tab-select 'tab-bar-select-tab)
(defalias 'tab-next 'tab-bar-switch-to-next-tab)
(defalias 'tab-previous 'tab-bar-switch-to-prev-tab)
(defalias 'tab-recent 'tab-bar-switch-to-recent-tab)
(defalias 'tab-move 'tab-bar-move-tab)
(defalias 'tab-move-to 'tab-bar-move-tab-to)
(defalias 'tab-rename 'tab-bar-rename-tab)