[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master dad47bf: * lisp/tab-bar.el: Sort tab names by recency for tab swi
From: |
Juri Linkov |
Subject: |
master dad47bf: * lisp/tab-bar.el: Sort tab names by recency for tab switching (bug#38624) |
Date: |
Thu, 19 Dec 2019 18:18:35 -0500 (EST) |
branch: master
commit dad47bff3d5740d8cacf1495e6becfb16a393bb0
Author: Juri Linkov <address@hidden>
Commit: Juri Linkov <address@hidden>
* lisp/tab-bar.el: Sort tab names by recency for tab switching (bug#38624)
* lisp/tab-bar.el (tab-bar--tabs-recent): New function with code
extracted from tab-bar--tab-index-recent.
(tab-bar-switch-to-tab): Use tab-bar--tabs-recent in interactive spec
to sort names of tabs by recency for default values of completing-read.
(tab-prefix-map): Bind RET to tab-bar-select-tab-by-name, and 'm' to
tab-move.
---
lisp/tab-bar.el | 36 ++++++++++++++++++++++--------------
1 file changed, 22 insertions(+), 14 deletions(-)
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index 92e11de..84388c6 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -508,14 +508,17 @@ Return its existing value or a new value."
(defun tab-bar--tab-index-recent (nth &optional tabs frame)
(let* ((tabs (or tabs (funcall tab-bar-tabs-function frame)))
- (sorted-tabs
- (seq-sort-by (lambda (tab) (cdr (assq 'time tab))) #'>
- (seq-remove (lambda (tab)
- (eq (car tab) 'current-tab))
- tabs)))
+ (sorted-tabs (tab-bar--tabs-recent tabs frame))
(tab (nth (1- nth) sorted-tabs)))
(tab-bar--tab-index tab tabs)))
+(defun tab-bar--tabs-recent (&optional tabs frame)
+ (let* ((tabs (or tabs (funcall tab-bar-tabs-function frame))))
+ (seq-sort-by (lambda (tab) (cdr (assq 'time tab))) #'>
+ (seq-remove (lambda (tab)
+ (eq (car tab) 'current-tab))
+ tabs))))
+
(defun tab-bar-select-tab (&optional arg)
"Switch to the tab by its absolute position ARG in the tab bar.
@@ -621,10 +624,12 @@ to the numeric argument. ARG counts from 1."
(defun tab-bar-switch-to-tab (name)
"Switch to the tab by NAME."
- (interactive (list (completing-read "Switch to tab by name: "
- (mapcar (lambda (tab)
- (cdr (assq 'name tab)))
- (funcall
tab-bar-tabs-function)))))
+ (interactive
+ (let* ((recent-tabs (mapcar (lambda (tab)
+ (cdr (assq 'name tab)))
+ (tab-bar--tabs-recent))))
+ (list (completing-read "Switch to tab by name (default recent): "
+ recent-tabs nil nil nil nil recent-tabs))))
(tab-bar-select-tab (1+ (tab-bar--tab-index-by-name name))))
(defalias 'tab-bar-select-tab-by-name 'tab-bar-switch-to-tab)
@@ -900,10 +905,11 @@ for the last tab on a frame is determined by
(defun tab-bar-close-tab-by-name (name)
"Close the tab by NAME."
- (interactive (list (completing-read "Close tab by name: "
- (mapcar (lambda (tab)
- (cdr (assq 'name tab)))
- (funcall
tab-bar-tabs-function)))))
+ (interactive
+ (list (completing-read "Close tab by name: "
+ (mapcar (lambda (tab)
+ (cdr (assq 'name tab)))
+ (funcall tab-bar-tabs-function)))))
(tab-bar-close-tab (1+ (tab-bar--tab-index-by-name name))))
(defun tab-bar-close-other-tabs ()
@@ -1479,10 +1485,12 @@ Like \\[find-file-other-frame] (which see), but creates
a new tab."
(define-key tab-prefix-map "1" 'tab-close-other)
(define-key tab-prefix-map "0" 'tab-close)
(define-key tab-prefix-map "o" 'tab-next)
+(define-key tab-prefix-map "m" 'tab-move)
+(define-key tab-prefix-map "r" 'tab-rename)
+(define-key tab-prefix-map "\r" 'tab-bar-select-tab-by-name)
(define-key tab-prefix-map "b" 'switch-to-buffer-other-tab)
(define-key tab-prefix-map "f" 'find-file-other-tab)
(define-key tab-prefix-map "\C-f" 'find-file-other-tab)
-(define-key tab-prefix-map "r" 'tab-rename)
(provide 'tab-bar)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master dad47bf: * lisp/tab-bar.el: Sort tab names by recency for tab switching (bug#38624),
Juri Linkov <=