diff options
| author | Juri Linkov | 2019-12-23 00:55:38 +0200 |
|---|---|---|
| committer | Juri Linkov | 2019-12-23 00:55:38 +0200 |
| commit | d7eb4955ebb77379a64c60d0eda4a112ca8c596c (patch) | |
| tree | 55aea01697c25ec4c1cfa331fe03246445331910 | |
| parent | 5e3670b685d413a2008659ac86dfa41923534fe8 (diff) | |
| download | emacs-d7eb4955ebb77379a64c60d0eda4a112ca8c596c.tar.gz emacs-d7eb4955ebb77379a64c60d0eda4a112ca8c596c.zip | |
* lisp/tab-bar.el: Use alist-get instead of (cdr (assq ...))
* lisp/tab-bar.el (tab-bar-mode): Bind s-0 to tab-bar-switch-to-recent-tab.
| -rw-r--r-- | lisp/tab-bar.el | 76 |
1 files changed, 39 insertions, 37 deletions
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el index ceeab1075bc..0d0197eb6bc 100644 --- a/lisp/tab-bar.el +++ b/lisp/tab-bar.el | |||
| @@ -144,6 +144,8 @@ Possible modifiers are `control', `meta', `shift', `hyper', `super' and | |||
| 144 | (if tab-bar-mode | 144 | (if tab-bar-mode |
| 145 | (progn | 145 | (progn |
| 146 | (when tab-bar-select-tab-modifiers | 146 | (when tab-bar-select-tab-modifiers |
| 147 | (global-set-key (vector (append tab-bar-select-tab-modifiers (list ?0))) | ||
| 148 | 'tab-bar-switch-to-recent-tab) | ||
| 147 | (dotimes (i 9) | 149 | (dotimes (i 9) |
| 148 | (global-set-key (vector (append tab-bar-select-tab-modifiers | 150 | (global-set-key (vector (append tab-bar-select-tab-modifiers |
| 149 | (list (+ i 1 ?0)))) | 151 | (list (+ i 1 ?0)))) |
| @@ -405,7 +407,7 @@ Return its existing value or a new value." | |||
| 405 | `((current-tab | 407 | `((current-tab |
| 406 | menu-item | 408 | menu-item |
| 407 | ,(propertize (concat (if tab-bar-tab-hints (format "%d " i) "") | 409 | ,(propertize (concat (if tab-bar-tab-hints (format "%d " i) "") |
| 408 | (cdr (assq 'name tab)) | 410 | (alist-get 'name tab) |
| 409 | (or (and tab-bar-close-button-show | 411 | (or (and tab-bar-close-button-show |
| 410 | (not (eq tab-bar-close-button-show | 412 | (not (eq tab-bar-close-button-show |
| 411 | 'non-selected)) | 413 | 'non-selected)) |
| @@ -417,14 +419,14 @@ Return its existing value or a new value." | |||
| 417 | `((,(intern (format "tab-%i" i)) | 419 | `((,(intern (format "tab-%i" i)) |
| 418 | menu-item | 420 | menu-item |
| 419 | ,(propertize (concat (if tab-bar-tab-hints (format "%d " i) "") | 421 | ,(propertize (concat (if tab-bar-tab-hints (format "%d " i) "") |
| 420 | (cdr (assq 'name tab)) | 422 | (alist-get 'name tab) |
| 421 | (or (and tab-bar-close-button-show | 423 | (or (and tab-bar-close-button-show |
| 422 | (not (eq tab-bar-close-button-show | 424 | (not (eq tab-bar-close-button-show |
| 423 | 'selected)) | 425 | 'selected)) |
| 424 | tab-bar-close-button) "")) | 426 | tab-bar-close-button) "")) |
| 425 | 'face 'tab-bar-tab-inactive) | 427 | 'face 'tab-bar-tab-inactive) |
| 426 | ,(or | 428 | ,(or |
| 427 | (cdr (assq 'binding tab)) | 429 | (alist-get 'binding tab) |
| 428 | `(lambda () | 430 | `(lambda () |
| 429 | (interactive) | 431 | (interactive) |
| 430 | (tab-bar-select-tab ,i))) | 432 | (tab-bar-select-tab ,i))) |
| @@ -432,7 +434,7 @@ Return its existing value or a new value." | |||
| 432 | `((,(if (eq (car tab) 'current-tab) 'C-current-tab (intern (format "C-tab-%i" i))) | 434 | `((,(if (eq (car tab) 'current-tab) 'C-current-tab (intern (format "C-tab-%i" i))) |
| 433 | menu-item "" | 435 | menu-item "" |
| 434 | ,(or | 436 | ,(or |
| 435 | (cdr (assq 'close-binding tab)) | 437 | (alist-get 'close-binding tab) |
| 436 | `(lambda () | 438 | `(lambda () |
| 437 | (interactive) | 439 | (interactive) |
| 438 | (tab-bar-close-tab ,i))))))) | 440 | (tab-bar-close-tab ,i))))))) |
| @@ -464,12 +466,12 @@ Return its existing value or a new value." | |||
| 464 | 466 | ||
| 465 | (defun tab-bar--tab (&optional frame) | 467 | (defun tab-bar--tab (&optional frame) |
| 466 | (let* ((tab (assq 'current-tab (frame-parameter frame 'tabs))) | 468 | (let* ((tab (assq 'current-tab (frame-parameter frame 'tabs))) |
| 467 | (tab-explicit-name (cdr (assq 'explicit-name tab))) | 469 | (tab-explicit-name (alist-get 'explicit-name tab)) |
| 468 | (bl (seq-filter #'buffer-live-p (frame-parameter frame 'buffer-list))) | 470 | (bl (seq-filter #'buffer-live-p (frame-parameter frame 'buffer-list))) |
| 469 | (bbl (seq-filter #'buffer-live-p (frame-parameter frame 'buried-buffer-list)))) | 471 | (bbl (seq-filter #'buffer-live-p (frame-parameter frame 'buried-buffer-list)))) |
| 470 | `(tab | 472 | `(tab |
| 471 | (name . ,(if tab-explicit-name | 473 | (name . ,(if tab-explicit-name |
| 472 | (cdr (assq 'name tab)) | 474 | (alist-get 'name tab) |
| 473 | (funcall tab-bar-tab-name-function))) | 475 | (funcall tab-bar-tab-name-function))) |
| 474 | (explicit-name . ,tab-explicit-name) | 476 | (explicit-name . ,tab-explicit-name) |
| 475 | (time . ,(float-time)) | 477 | (time . ,(float-time)) |
| @@ -487,10 +489,10 @@ Return its existing value or a new value." | |||
| 487 | ;; necessary when switching tabs, otherwise the destination tab | 489 | ;; necessary when switching tabs, otherwise the destination tab |
| 488 | ;; inherit the current tab's `explicit-name` parameter. | 490 | ;; inherit the current tab's `explicit-name` parameter. |
| 489 | (let* ((tab (or tab (assq 'current-tab (frame-parameter frame 'tabs)))) | 491 | (let* ((tab (or tab (assq 'current-tab (frame-parameter frame 'tabs)))) |
| 490 | (tab-explicit-name (cdr (assq 'explicit-name tab)))) | 492 | (tab-explicit-name (alist-get 'explicit-name tab))) |
| 491 | `(current-tab | 493 | `(current-tab |
| 492 | (name . ,(if tab-explicit-name | 494 | (name . ,(if tab-explicit-name |
| 493 | (cdr (assq 'name tab)) | 495 | (alist-get 'name tab) |
| 494 | (funcall tab-bar-tab-name-function))) | 496 | (funcall tab-bar-tab-name-function))) |
| 495 | (explicit-name . ,tab-explicit-name)))) | 497 | (explicit-name . ,tab-explicit-name)))) |
| 496 | 498 | ||
| @@ -504,7 +506,7 @@ Return its existing value or a new value." | |||
| 504 | 506 | ||
| 505 | (defun tab-bar--tab-index-by-name (name &optional tabs frame) | 507 | (defun tab-bar--tab-index-by-name (name &optional tabs frame) |
| 506 | (seq-position (or tabs (funcall tab-bar-tabs-function frame)) | 508 | (seq-position (or tabs (funcall tab-bar-tabs-function frame)) |
| 507 | name (lambda (a b) (equal (cdr (assq 'name a)) b)))) | 509 | name (lambda (a b) (equal (alist-get 'name a) b)))) |
| 508 | 510 | ||
| 509 | (defun tab-bar--tab-index-recent (nth &optional tabs frame) | 511 | (defun tab-bar--tab-index-recent (nth &optional tabs frame) |
| 510 | (let* ((tabs (or tabs (funcall tab-bar-tabs-function frame))) | 512 | (let* ((tabs (or tabs (funcall tab-bar-tabs-function frame))) |
| @@ -514,7 +516,7 @@ Return its existing value or a new value." | |||
| 514 | 516 | ||
| 515 | (defun tab-bar--tabs-recent (&optional tabs frame) | 517 | (defun tab-bar--tabs-recent (&optional tabs frame) |
| 516 | (let* ((tabs (or tabs (funcall tab-bar-tabs-function frame)))) | 518 | (let* ((tabs (or tabs (funcall tab-bar-tabs-function frame)))) |
| 517 | (seq-sort-by (lambda (tab) (cdr (assq 'time tab))) #'> | 519 | (seq-sort-by (lambda (tab) (alist-get 'time tab)) #'> |
| 518 | (seq-remove (lambda (tab) | 520 | (seq-remove (lambda (tab) |
| 519 | (eq (car tab) 'current-tab)) | 521 | (eq (car tab) 'current-tab)) |
| 520 | tabs)))) | 522 | tabs)))) |
| @@ -538,8 +540,8 @@ to the numeric argument. ARG counts from 1." | |||
| 538 | (unless (eq from-index to-index) | 540 | (unless (eq from-index to-index) |
| 539 | (let* ((from-tab (tab-bar--tab)) | 541 | (let* ((from-tab (tab-bar--tab)) |
| 540 | (to-tab (nth to-index tabs)) | 542 | (to-tab (nth to-index tabs)) |
| 541 | (wc (cdr (assq 'wc to-tab))) | 543 | (wc (alist-get 'wc to-tab)) |
| 542 | (ws (cdr (assq 'ws to-tab)))) | 544 | (ws (alist-get 'ws to-tab))) |
| 543 | 545 | ||
| 544 | ;; During the same session, use window-configuration to switch | 546 | ;; During the same session, use window-configuration to switch |
| 545 | ;; tabs, because window-configurations are more reliable | 547 | ;; tabs, because window-configurations are more reliable |
| @@ -549,11 +551,11 @@ to the numeric argument. ARG counts from 1." | |||
| 549 | ;; so restore its saved window-state. | 551 | ;; so restore its saved window-state. |
| 550 | (cond | 552 | (cond |
| 551 | ((window-configuration-p wc) | 553 | ((window-configuration-p wc) |
| 552 | (let ((wc-point (cdr (assq 'wc-point to-tab))) | 554 | (let ((wc-point (alist-get 'wc-point to-tab)) |
| 553 | (wc-bl (seq-filter #'buffer-live-p (cdr (assq 'wc-bl to-tab)))) | 555 | (wc-bl (seq-filter #'buffer-live-p (alist-get 'wc-bl to-tab))) |
| 554 | (wc-bbl (seq-filter #'buffer-live-p (cdr (assq 'wc-bbl to-tab)))) | 556 | (wc-bbl (seq-filter #'buffer-live-p (alist-get 'wc-bbl to-tab))) |
| 555 | (wc-history-back (cdr (assq 'wc-history-back to-tab))) | 557 | (wc-history-back (alist-get 'wc-history-back to-tab)) |
| 556 | (wc-history-forward (cdr (assq 'wc-history-forward to-tab)))) | 558 | (wc-history-forward (alist-get 'wc-history-forward to-tab))) |
| 557 | 559 | ||
| 558 | (set-window-configuration wc) | 560 | (set-window-configuration wc) |
| 559 | 561 | ||
| @@ -573,11 +575,11 @@ to the numeric argument. ARG counts from 1." | |||
| 573 | (when wc-bbl (set-frame-parameter nil 'buried-buffer-list wc-bbl)) | 575 | (when wc-bbl (set-frame-parameter nil 'buried-buffer-list wc-bbl)) |
| 574 | 576 | ||
| 575 | (puthash (selected-frame) | 577 | (puthash (selected-frame) |
| 576 | (and (window-configuration-p (cdr (assq 'wc (car wc-history-back)))) | 578 | (and (window-configuration-p (alist-get 'wc (car wc-history-back))) |
| 577 | wc-history-back) | 579 | wc-history-back) |
| 578 | tab-bar-history-back) | 580 | tab-bar-history-back) |
| 579 | (puthash (selected-frame) | 581 | (puthash (selected-frame) |
| 580 | (and (window-configuration-p (cdr (assq 'wc (car wc-history-forward)))) | 582 | (and (window-configuration-p (alist-get 'wc (car wc-history-forward))) |
| 581 | wc-history-forward) | 583 | wc-history-forward) |
| 582 | tab-bar-history-forward))) | 584 | tab-bar-history-forward))) |
| 583 | 585 | ||
| @@ -626,7 +628,7 @@ to the numeric argument. ARG counts from 1." | |||
| 626 | "Switch to the tab by NAME." | 628 | "Switch to the tab by NAME." |
| 627 | (interactive | 629 | (interactive |
| 628 | (let* ((recent-tabs (mapcar (lambda (tab) | 630 | (let* ((recent-tabs (mapcar (lambda (tab) |
| 629 | (cdr (assq 'name tab))) | 631 | (alist-get 'name tab)) |
| 630 | (tab-bar--tabs-recent)))) | 632 | (tab-bar--tabs-recent)))) |
| 631 | (list (completing-read "Switch to tab by name (default recent): " | 633 | (list (completing-read "Switch to tab by name (default recent): " |
| 632 | recent-tabs nil nil nil nil recent-tabs)))) | 634 | recent-tabs nil nil nil nil recent-tabs)))) |
| @@ -908,7 +910,7 @@ for the last tab on a frame is determined by | |||
| 908 | (interactive | 910 | (interactive |
| 909 | (list (completing-read "Close tab by name: " | 911 | (list (completing-read "Close tab by name: " |
| 910 | (mapcar (lambda (tab) | 912 | (mapcar (lambda (tab) |
| 911 | (cdr (assq 'name tab))) | 913 | (alist-get 'name tab)) |
| 912 | (funcall tab-bar-tabs-function))))) | 914 | (funcall tab-bar-tabs-function))))) |
| 913 | (tab-bar-close-tab (1+ (tab-bar--tab-index-by-name name)))) | 915 | (tab-bar-close-tab (1+ (tab-bar--tab-index-by-name name)))) |
| 914 | 916 | ||
| @@ -947,14 +949,14 @@ for the last tab on a frame is determined by | |||
| 947 | (interactive) | 949 | (interactive) |
| 948 | ;; Pop out closed tabs that were on already deleted frames | 950 | ;; Pop out closed tabs that were on already deleted frames |
| 949 | (while (and tab-bar-closed-tabs | 951 | (while (and tab-bar-closed-tabs |
| 950 | (not (frame-live-p (cdr (assq 'frame (car tab-bar-closed-tabs)))))) | 952 | (not (frame-live-p (alist-get 'frame (car tab-bar-closed-tabs))))) |
| 951 | (pop tab-bar-closed-tabs)) | 953 | (pop tab-bar-closed-tabs)) |
| 952 | 954 | ||
| 953 | (if tab-bar-closed-tabs | 955 | (if tab-bar-closed-tabs |
| 954 | (let* ((closed (pop tab-bar-closed-tabs)) | 956 | (let* ((closed (pop tab-bar-closed-tabs)) |
| 955 | (frame (cdr (assq 'frame closed))) | 957 | (frame (alist-get 'frame closed)) |
| 956 | (index (cdr (assq 'index closed))) | 958 | (index (alist-get 'index closed)) |
| 957 | (tab (cdr (assq 'tab closed)))) | 959 | (tab (alist-get 'tab closed))) |
| 958 | (unless (eq frame (selected-frame)) | 960 | (unless (eq frame (selected-frame)) |
| 959 | (select-frame-set-input-focus frame)) | 961 | (select-frame-set-input-focus frame)) |
| 960 | 962 | ||
| @@ -978,7 +980,7 @@ function `tab-bar-tab-name-function'." | |||
| 978 | (interactive | 980 | (interactive |
| 979 | (let* ((tabs (funcall tab-bar-tabs-function)) | 981 | (let* ((tabs (funcall tab-bar-tabs-function)) |
| 980 | (tab-index (or current-prefix-arg (1+ (tab-bar--current-tab-index tabs)))) | 982 | (tab-index (or current-prefix-arg (1+ (tab-bar--current-tab-index tabs)))) |
| 981 | (tab-name (cdr (assq 'name (nth (1- tab-index) tabs))))) | 983 | (tab-name (alist-get 'name (nth (1- tab-index) tabs)))) |
| 982 | (list (read-from-minibuffer | 984 | (list (read-from-minibuffer |
| 983 | "New name for tab (leave blank for automatic naming): " | 985 | "New name for tab (leave blank for automatic naming): " |
| 984 | nil nil nil nil tab-name) | 986 | nil nil nil nil tab-name) |
| @@ -992,8 +994,8 @@ function `tab-bar-tab-name-function'." | |||
| 992 | (tab-new-name (if tab-explicit-name | 994 | (tab-new-name (if tab-explicit-name |
| 993 | name | 995 | name |
| 994 | (funcall tab-bar-tab-name-function)))) | 996 | (funcall tab-bar-tab-name-function)))) |
| 995 | (setf (cdr (assq 'name tab-to-rename)) tab-new-name | 997 | (setf (alist-get 'name tab-to-rename) tab-new-name |
| 996 | (cdr (assq 'explicit-name tab-to-rename)) tab-explicit-name) | 998 | (alist-get 'explicit-name tab-to-rename) tab-explicit-name) |
| 997 | 999 | ||
| 998 | (force-mode-line-update) | 1000 | (force-mode-line-update) |
| 999 | (unless tab-bar-mode | 1001 | (unless tab-bar-mode |
| @@ -1006,7 +1008,7 @@ function `tab-bar-tab-name-function'." | |||
| 1006 | (interactive | 1008 | (interactive |
| 1007 | (let ((tab-name (completing-read "Rename tab by name: " | 1009 | (let ((tab-name (completing-read "Rename tab by name: " |
| 1008 | (mapcar (lambda (tab) | 1010 | (mapcar (lambda (tab) |
| 1009 | (cdr (assq 'name tab))) | 1011 | (alist-get 'name tab)) |
| 1010 | (funcall tab-bar-tabs-function))))) | 1012 | (funcall tab-bar-tabs-function))))) |
| 1011 | (list tab-name (read-from-minibuffer | 1013 | (list tab-name (read-from-minibuffer |
| 1012 | "New name for tab (leave blank for automatic naming): " | 1014 | "New name for tab (leave blank for automatic naming): " |
| @@ -1059,8 +1061,8 @@ function `tab-bar-tab-name-function'." | |||
| 1059 | (interactive) | 1061 | (interactive) |
| 1060 | (setq tab-bar-history-omit t) | 1062 | (setq tab-bar-history-omit t) |
| 1061 | (let* ((history (pop (gethash (selected-frame) tab-bar-history-back))) | 1063 | (let* ((history (pop (gethash (selected-frame) tab-bar-history-back))) |
| 1062 | (wc (cdr (assq 'wc history))) | 1064 | (wc (alist-get 'wc history)) |
| 1063 | (wc-point (cdr (assq 'wc-point history)))) | 1065 | (wc-point (alist-get 'wc-point history))) |
| 1064 | (if (window-configuration-p wc) | 1066 | (if (window-configuration-p wc) |
| 1065 | (progn | 1067 | (progn |
| 1066 | (puthash (selected-frame) | 1068 | (puthash (selected-frame) |
| @@ -1076,8 +1078,8 @@ function `tab-bar-tab-name-function'." | |||
| 1076 | (interactive) | 1078 | (interactive) |
| 1077 | (setq tab-bar-history-omit t) | 1079 | (setq tab-bar-history-omit t) |
| 1078 | (let* ((history (pop (gethash (selected-frame) tab-bar-history-forward))) | 1080 | (let* ((history (pop (gethash (selected-frame) tab-bar-history-forward))) |
| 1079 | (wc (cdr (assq 'wc history))) | 1081 | (wc (alist-get 'wc history)) |
| 1080 | (wc-point (cdr (assq 'wc-point history)))) | 1082 | (wc-point (alist-get 'wc-point history))) |
| 1081 | (if (window-configuration-p wc) | 1083 | (if (window-configuration-p wc) |
| 1082 | (progn | 1084 | (progn |
| 1083 | (puthash (selected-frame) | 1085 | (puthash (selected-frame) |
| @@ -1175,8 +1177,8 @@ For more information, see the function `tab-switcher'." | |||
| 1175 | (eq (car tab) 'current-tab)) | 1177 | (eq (car tab) 'current-tab)) |
| 1176 | (funcall tab-bar-tabs-function))) | 1178 | (funcall tab-bar-tabs-function))) |
| 1177 | ;; Sort by recency | 1179 | ;; Sort by recency |
| 1178 | (tabs (sort tabs (lambda (a b) (< (cdr (assq 'time b)) | 1180 | (tabs (sort tabs (lambda (a b) (< (alist-get 'time b) |
| 1179 | (cdr (assq 'time a))))))) | 1181 | (alist-get 'time a)))))) |
| 1180 | (with-current-buffer (get-buffer-create | 1182 | (with-current-buffer (get-buffer-create |
| 1181 | (format " *Tabs*<%s>" (or (frame-parameter nil 'window-id) | 1183 | (format " *Tabs*<%s>" (or (frame-parameter nil 'window-id) |
| 1182 | (frame-parameter nil 'name)))) | 1184 | (frame-parameter nil 'name)))) |
| @@ -1192,7 +1194,7 @@ For more information, see the function `tab-switcher'." | |||
| 1192 | (format "%s %s\n" | 1194 | (format "%s %s\n" |
| 1193 | (make-string tab-switcher-column ?\040) | 1195 | (make-string tab-switcher-column ?\040) |
| 1194 | (propertize | 1196 | (propertize |
| 1195 | (cdr (assq 'name tab)) | 1197 | (alist-get 'name tab) |
| 1196 | 'mouse-face 'highlight | 1198 | 'mouse-face 'highlight |
| 1197 | 'help-echo "mouse-2: select this window configuration")) | 1199 | 'help-echo "mouse-2: select this window configuration")) |
| 1198 | 'tab tab))) | 1200 | 'tab tab))) |
| @@ -1393,7 +1395,7 @@ selected frame and no others." | |||
| 1393 | (lambda (tab) | 1395 | (lambda (tab) |
| 1394 | (when (if (eq (car tab) 'current-tab) | 1396 | (when (if (eq (car tab) 'current-tab) |
| 1395 | (get-buffer-window buffer frame) | 1397 | (get-buffer-window buffer frame) |
| 1396 | (let* ((state (cdr (assq 'ws tab))) | 1398 | (let* ((state (alist-get 'ws tab)) |
| 1397 | (buffers (when state | 1399 | (buffers (when state |
| 1398 | (window-state-buffers state)))) | 1400 | (window-state-buffers state)))) |
| 1399 | (or | 1401 | (or |