diff options
| author | Juri Linkov | 2019-12-20 01:18:28 +0200 |
|---|---|---|
| committer | Juri Linkov | 2019-12-20 01:18:28 +0200 |
| commit | dad47bff3d5740d8cacf1495e6becfb16a393bb0 (patch) | |
| tree | a088d41ea16dd178d1926db5dfa1e862f6639082 /lisp | |
| parent | 0bc00cda3cb6e765b0e1f0105edf75425bce13c9 (diff) | |
| download | emacs-dad47bff3d5740d8cacf1495e6becfb16a393bb0.tar.gz emacs-dad47bff3d5740d8cacf1495e6becfb16a393bb0.zip | |
* 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.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/tab-bar.el | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el index 92e11dec394..84388c6cc93 100644 --- a/lisp/tab-bar.el +++ b/lisp/tab-bar.el | |||
| @@ -508,14 +508,17 @@ Return its existing value or a new value." | |||
| 508 | 508 | ||
| 509 | (defun tab-bar--tab-index-recent (nth &optional tabs frame) | 509 | (defun tab-bar--tab-index-recent (nth &optional tabs frame) |
| 510 | (let* ((tabs (or tabs (funcall tab-bar-tabs-function frame))) | 510 | (let* ((tabs (or tabs (funcall tab-bar-tabs-function frame))) |
| 511 | (sorted-tabs | 511 | (sorted-tabs (tab-bar--tabs-recent tabs frame)) |
| 512 | (seq-sort-by (lambda (tab) (cdr (assq 'time tab))) #'> | ||
| 513 | (seq-remove (lambda (tab) | ||
| 514 | (eq (car tab) 'current-tab)) | ||
| 515 | tabs))) | ||
| 516 | (tab (nth (1- nth) sorted-tabs))) | 512 | (tab (nth (1- nth) sorted-tabs))) |
| 517 | (tab-bar--tab-index tab tabs))) | 513 | (tab-bar--tab-index tab tabs))) |
| 518 | 514 | ||
| 515 | (defun tab-bar--tabs-recent (&optional tabs frame) | ||
| 516 | (let* ((tabs (or tabs (funcall tab-bar-tabs-function frame)))) | ||
| 517 | (seq-sort-by (lambda (tab) (cdr (assq 'time tab))) #'> | ||
| 518 | (seq-remove (lambda (tab) | ||
| 519 | (eq (car tab) 'current-tab)) | ||
| 520 | tabs)))) | ||
| 521 | |||
| 519 | 522 | ||
| 520 | (defun tab-bar-select-tab (&optional arg) | 523 | (defun tab-bar-select-tab (&optional arg) |
| 521 | "Switch to the tab by its absolute position ARG in the tab bar. | 524 | "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." | |||
| 621 | 624 | ||
| 622 | (defun tab-bar-switch-to-tab (name) | 625 | (defun tab-bar-switch-to-tab (name) |
| 623 | "Switch to the tab by NAME." | 626 | "Switch to the tab by NAME." |
| 624 | (interactive (list (completing-read "Switch to tab by name: " | 627 | (interactive |
| 625 | (mapcar (lambda (tab) | 628 | (let* ((recent-tabs (mapcar (lambda (tab) |
| 626 | (cdr (assq 'name tab))) | 629 | (cdr (assq 'name tab))) |
| 627 | (funcall tab-bar-tabs-function))))) | 630 | (tab-bar--tabs-recent)))) |
| 631 | (list (completing-read "Switch to tab by name (default recent): " | ||
| 632 | recent-tabs nil nil nil nil recent-tabs)))) | ||
| 628 | (tab-bar-select-tab (1+ (tab-bar--tab-index-by-name name)))) | 633 | (tab-bar-select-tab (1+ (tab-bar--tab-index-by-name name)))) |
| 629 | 634 | ||
| 630 | (defalias 'tab-bar-select-tab-by-name 'tab-bar-switch-to-tab) | 635 | (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 | |||
| 900 | 905 | ||
| 901 | (defun tab-bar-close-tab-by-name (name) | 906 | (defun tab-bar-close-tab-by-name (name) |
| 902 | "Close the tab by NAME." | 907 | "Close the tab by NAME." |
| 903 | (interactive (list (completing-read "Close tab by name: " | 908 | (interactive |
| 904 | (mapcar (lambda (tab) | 909 | (list (completing-read "Close tab by name: " |
| 905 | (cdr (assq 'name tab))) | 910 | (mapcar (lambda (tab) |
| 906 | (funcall tab-bar-tabs-function))))) | 911 | (cdr (assq 'name tab))) |
| 912 | (funcall tab-bar-tabs-function))))) | ||
| 907 | (tab-bar-close-tab (1+ (tab-bar--tab-index-by-name name)))) | 913 | (tab-bar-close-tab (1+ (tab-bar--tab-index-by-name name)))) |
| 908 | 914 | ||
| 909 | (defun tab-bar-close-other-tabs () | 915 | (defun tab-bar-close-other-tabs () |
| @@ -1479,10 +1485,12 @@ Like \\[find-file-other-frame] (which see), but creates a new tab." | |||
| 1479 | (define-key tab-prefix-map "1" 'tab-close-other) | 1485 | (define-key tab-prefix-map "1" 'tab-close-other) |
| 1480 | (define-key tab-prefix-map "0" 'tab-close) | 1486 | (define-key tab-prefix-map "0" 'tab-close) |
| 1481 | (define-key tab-prefix-map "o" 'tab-next) | 1487 | (define-key tab-prefix-map "o" 'tab-next) |
| 1488 | (define-key tab-prefix-map "m" 'tab-move) | ||
| 1489 | (define-key tab-prefix-map "r" 'tab-rename) | ||
| 1490 | (define-key tab-prefix-map "\r" 'tab-bar-select-tab-by-name) | ||
| 1482 | (define-key tab-prefix-map "b" 'switch-to-buffer-other-tab) | 1491 | (define-key tab-prefix-map "b" 'switch-to-buffer-other-tab) |
| 1483 | (define-key tab-prefix-map "f" 'find-file-other-tab) | 1492 | (define-key tab-prefix-map "f" 'find-file-other-tab) |
| 1484 | (define-key tab-prefix-map "\C-f" 'find-file-other-tab) | 1493 | (define-key tab-prefix-map "\C-f" 'find-file-other-tab) |
| 1485 | (define-key tab-prefix-map "r" 'tab-rename) | ||
| 1486 | 1494 | ||
| 1487 | 1495 | ||
| 1488 | (provide 'tab-bar) | 1496 | (provide 'tab-bar) |