aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2019-10-16 00:42:31 +0300
committerJuri Linkov2019-10-16 00:42:31 +0300
commit2912de1e1079bfa4e975e6414e171d747c83c202 (patch)
tree50a141f78534e1e6b8f0611b73568a4732eae433
parentbf112e23ef7b2939ff40c0c1f94adce4ffa79187 (diff)
downloademacs-2912de1e1079bfa4e975e6414e171d747c83c202.tar.gz
emacs-2912de1e1079bfa4e975e6414e171d747c83c202.zip
Declare tab-bar-tabs the single source of truth in regard to current tab name
* lisp/tab-bar.el: Replace all calls of tab-bar-tabs with '(funcall tab-bar-tabs-function)'. (tab-bar-tabs): Update the current tab name here instead of tab-bar-make-keymap-1. (tab-bar-make-keymap-1): Move the current tab name updating to tab-bar-tabs.
-rw-r--r--lisp/tab-bar.el56
1 files changed, 29 insertions, 27 deletions
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index 32d7f6c784b..c376f598966 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -230,7 +230,8 @@ keyboard commands `tab-list', `tab-new', `tab-close', `tab-next', etc."
230 (set-default sym val) 230 (set-default sym val)
231 (tab-bar-mode 231 (tab-bar-mode
232 (if (or (eq val t) 232 (if (or (eq val t)
233 (and (natnump val) (> (length (tab-bar-tabs)) val))) 233 (and (natnump val)
234 (> (length (funcall tab-bar-tabs-function)) val)))
234 1 -1))) 235 1 -1)))
235 :group 'tab-bar 236 :group 'tab-bar
236 :version "27.1") 237 :version "27.1")
@@ -346,9 +347,18 @@ By default, use function `tab-bar-tabs'.")
346(defun tab-bar-tabs () 347(defun tab-bar-tabs ()
347 "Return a list of tabs belonging to the selected frame. 348 "Return a list of tabs belonging to the selected frame.
348Ensure the frame parameter `tabs' is pre-populated. 349Ensure the frame parameter `tabs' is pre-populated.
350Update the current tab name when it exists.
349Return its existing value or a new value." 351Return its existing value or a new value."
350 (let ((tabs (frame-parameter nil 'tabs))) 352 (let ((tabs (frame-parameter nil 'tabs)))
351 (unless tabs 353 (if tabs
354 (let* ((current-tab (assq 'current-tab tabs))
355 (current-tab-name (assq 'name current-tab))
356 (current-tab-explicit-name (assq 'explicit-name current-tab)))
357 (when (and current-tab-name
358 current-tab-explicit-name
359 (not (cdr current-tab-explicit-name)))
360 (setf (cdr current-tab-name)
361 (funcall tab-bar-tab-name-function))))
352 ;; Create default tabs 362 ;; Create default tabs
353 (setq tabs (list (tab-bar--current-tab))) 363 (setq tabs (list (tab-bar--current-tab)))
354 (set-frame-parameter nil 'tabs tabs)) 364 (set-frame-parameter nil 'tabs tabs))
@@ -358,14 +368,7 @@ Return its existing value or a new value."
358 "Generate an actual keymap from `tab-bar-map', without caching." 368 "Generate an actual keymap from `tab-bar-map', without caching."
359 (let* ((separator (or tab-bar-separator (if window-system " " "|"))) 369 (let* ((separator (or tab-bar-separator (if window-system " " "|")))
360 (i 0) 370 (i 0)
361 (tabs (funcall tab-bar-tabs-function)) 371 (tabs (funcall tab-bar-tabs-function)))
362 (current-tab-name (assq 'name (assq 'current-tab tabs)))
363 (current-tab-explicit-name (assq 'explicit-name (assq 'current-tab tabs))))
364 (when (and current-tab-name
365 current-tab-explicit-name
366 (not (cdr current-tab-explicit-name)))
367 (setf (cdr current-tab-name)
368 (funcall tab-bar-tab-name-function)))
369 (append 372 (append
370 '(keymap (mouse-1 . tab-bar-handle-mouse)) 373 '(keymap (mouse-1 . tab-bar-handle-mouse))
371 (mapcan 374 (mapcan
@@ -443,7 +446,7 @@ Return its existing value or a new value."
443 446
444(defun tab-bar--current-tab-index (&optional tabs) 447(defun tab-bar--current-tab-index (&optional tabs)
445 ;; FIXME: could be replaced with 1-liner using seq-position 448 ;; FIXME: could be replaced with 1-liner using seq-position
446 (let ((tabs (or tabs (tab-bar-tabs))) 449 (let ((tabs (or tabs (funcall tab-bar-tabs-function)))
447 (i 0)) 450 (i 0))
448 (catch 'done 451 (catch 'done
449 (while tabs 452 (while tabs
@@ -453,7 +456,7 @@ Return its existing value or a new value."
453 456
454(defun tab-bar--tab-index (tab &optional tabs) 457(defun tab-bar--tab-index (tab &optional tabs)
455 ;; FIXME: could be replaced with 1-liner using seq-position 458 ;; FIXME: could be replaced with 1-liner using seq-position
456 (let ((tabs (or tabs (tab-bar-tabs))) 459 (let ((tabs (or tabs (funcall tab-bar-tabs-function)))
457 (i 0)) 460 (i 0))
458 (catch 'done 461 (catch 'done
459 (while tabs 462 (while tabs
@@ -464,7 +467,7 @@ Return its existing value or a new value."
464 467
465(defun tab-bar--tab-index-by-name (name &optional tabs) 468(defun tab-bar--tab-index-by-name (name &optional tabs)
466 ;; FIXME: could be replaced with 1-liner using seq-position 469 ;; FIXME: could be replaced with 1-liner using seq-position
467 (let ((tabs (or tabs (tab-bar-tabs))) 470 (let ((tabs (or tabs (funcall tab-bar-tabs-function)))
468 (i 0)) 471 (i 0))
469 (catch 'done 472 (catch 'done
470 (while tabs 473 (while tabs
@@ -486,7 +489,7 @@ to the numeric argument. ARG counts from 1."
486 (- key ?0) 489 (- key ?0)
487 1)))) 490 1))))
488 491
489 (let* ((tabs (tab-bar-tabs)) 492 (let* ((tabs (funcall tab-bar-tabs-function))
490 (from-index (tab-bar--current-tab-index tabs)) 493 (from-index (tab-bar--current-tab-index tabs))
491 (to-index (1- (max 1 (min arg (length tabs)))))) 494 (to-index (1- (max 1 (min arg (length tabs))))))
492 (unless (eq from-index to-index) 495 (unless (eq from-index to-index)
@@ -518,7 +521,7 @@ to the numeric argument. ARG counts from 1."
518 (interactive "p") 521 (interactive "p")
519 (unless (integerp arg) 522 (unless (integerp arg)
520 (setq arg 1)) 523 (setq arg 1))
521 (let* ((tabs (tab-bar-tabs)) 524 (let* ((tabs (funcall tab-bar-tabs-function))
522 (from-index (or (tab-bar--current-tab-index tabs) 0)) 525 (from-index (or (tab-bar--current-tab-index tabs) 0))
523 (to-index (mod (+ from-index arg) (length tabs)))) 526 (to-index (mod (+ from-index arg) (length tabs))))
524 (tab-bar-select-tab (1+ to-index)))) 527 (tab-bar-select-tab (1+ to-index))))
@@ -535,7 +538,7 @@ to the numeric argument. ARG counts from 1."
535 (interactive (list (completing-read "Switch to tab by name: " 538 (interactive (list (completing-read "Switch to tab by name: "
536 (mapcar (lambda (tab) 539 (mapcar (lambda (tab)
537 (cdr (assq 'name tab))) 540 (cdr (assq 'name tab)))
538 (tab-bar-tabs))))) 541 (funcall tab-bar-tabs-function)))))
539 (tab-bar-select-tab (1+ (tab-bar--tab-index-by-name name)))) 542 (tab-bar-select-tab (1+ (tab-bar--tab-index-by-name name))))
540 543
541 544
@@ -555,7 +558,7 @@ If `rightmost', create as the last tab."
555(defun tab-bar-new-tab () 558(defun tab-bar-new-tab ()
556 "Add a new tab at the position specified by `tab-bar-new-tab-to'." 559 "Add a new tab at the position specified by `tab-bar-new-tab-to'."
557 (interactive) 560 (interactive)
558 (let* ((tabs (tab-bar-tabs)) 561 (let* ((tabs (funcall tab-bar-tabs-function))
559 (from-index (tab-bar--current-tab-index tabs)) 562 (from-index (tab-bar--current-tab-index tabs))
560 (from-tab (tab-bar--tab))) 563 (from-tab (tab-bar--tab)))
561 564
@@ -616,7 +619,7 @@ Optional TO-INDEX could be specified to override the value of
616of an existing tab to select after closing the current tab. 619of an existing tab to select after closing the current tab.
617TO-INDEX counts from 1." 620TO-INDEX counts from 1."
618 (interactive "P") 621 (interactive "P")
619 (let* ((tabs (tab-bar-tabs)) 622 (let* ((tabs (funcall tab-bar-tabs-function))
620 (current-index (tab-bar--current-tab-index tabs)) 623 (current-index (tab-bar--current-tab-index tabs))
621 (close-index (if (integerp arg) (1- arg) current-index))) 624 (close-index (if (integerp arg) (1- arg) current-index)))
622 625
@@ -631,7 +634,7 @@ TO-INDEX counts from 1."
631 (setq to-index (max 0 (min (or to-index 0) (1- (length tabs))))) 634 (setq to-index (max 0 (min (or to-index 0) (1- (length tabs)))))
632 (tab-bar-select-tab (1+ to-index)) 635 (tab-bar-select-tab (1+ to-index))
633 ;; Re-read tabs after selecting another tab 636 ;; Re-read tabs after selecting another tab
634 (setq tabs (tab-bar-tabs)))) 637 (setq tabs (funcall tab-bar-tabs-function))))
635 638
636 (set-frame-parameter nil 'tabs (delq (nth close-index tabs) tabs)) 639 (set-frame-parameter nil 'tabs (delq (nth close-index tabs) tabs))
637 640
@@ -648,13 +651,13 @@ TO-INDEX counts from 1."
648 (interactive (list (completing-read "Close tab by name: " 651 (interactive (list (completing-read "Close tab by name: "
649 (mapcar (lambda (tab) 652 (mapcar (lambda (tab)
650 (cdr (assq 'name tab))) 653 (cdr (assq 'name tab)))
651 (tab-bar-tabs))))) 654 (funcall tab-bar-tabs-function)))))
652 (tab-bar-close-tab (1+ (tab-bar--tab-index-by-name name)))) 655 (tab-bar-close-tab (1+ (tab-bar--tab-index-by-name name))))
653 656
654(defun tab-bar-close-other-tabs () 657(defun tab-bar-close-other-tabs ()
655 "Close all tabs on the selected frame, except the selected one." 658 "Close all tabs on the selected frame, except the selected one."
656 (interactive) 659 (interactive)
657 (let* ((tabs (tab-bar-tabs)) 660 (let* ((tabs (funcall tab-bar-tabs-function))
658 (current-index (tab-bar--current-tab-index tabs))) 661 (current-index (tab-bar--current-tab-index tabs)))
659 (when current-index 662 (when current-index
660 (set-frame-parameter nil 'tabs (list (nth current-index tabs))) 663 (set-frame-parameter nil 'tabs (list (nth current-index tabs)))
@@ -673,7 +676,7 @@ ARG counts from 1.
673If NAME is the empty string, then use the automatic name 676If NAME is the empty string, then use the automatic name
674function `tab-bar-tab-name-function'." 677function `tab-bar-tab-name-function'."
675 (interactive "sNew name for tab (leave blank for automatic naming): \nP") 678 (interactive "sNew name for tab (leave blank for automatic naming): \nP")
676 (let* ((tabs (tab-bar-tabs)) 679 (let* ((tabs (funcall tab-bar-tabs-function))
677 (tab-index (if arg 680 (tab-index (if arg
678 (1- (max 0 (min arg (length tabs)))) 681 (1- (max 0 (min arg (length tabs))))
679 (tab-bar--current-tab-index tabs))) 682 (tab-bar--current-tab-index tabs)))
@@ -683,8 +686,7 @@ function `tab-bar-tab-name-function'."
683 name 686 name
684 (funcall tab-bar-tab-name-function)))) 687 (funcall tab-bar-tab-name-function))))
685 (setf (cdr (assq 'name tab-to-rename)) tab-new-name 688 (setf (cdr (assq 'name tab-to-rename)) tab-new-name
686 (cdr (assq 'explicit-name tab-to-rename)) tab-explicit-name 689 (cdr (assq 'explicit-name tab-to-rename)) tab-explicit-name)
687 (frame-parameter nil 'tabs) tabs)
688 (if (tab-bar-mode) 690 (if (tab-bar-mode)
689 (force-mode-line-update) 691 (force-mode-line-update)
690 (message "Renamed tab to '%s'" tab-new-name)))) 692 (message "Renamed tab to '%s'" tab-new-name))))
@@ -696,7 +698,7 @@ function `tab-bar-tab-name-function'."
696 (interactive (list (completing-read "Rename tab by name: " 698 (interactive (list (completing-read "Rename tab by name: "
697 (mapcar (lambda (tab) 699 (mapcar (lambda (tab)
698 (cdr (assq 'name tab))) 700 (cdr (assq 'name tab)))
699 (tab-bar-tabs))) 701 (funcall tab-bar-tabs-function)))
700 (read-from-minibuffer "New name for tab (leave blank for automatic naming): "))) 702 (read-from-minibuffer "New name for tab (leave blank for automatic naming): ")))
701 (tab-bar-rename-tab new-name (tab-bar--tab-index-by-name tab-name))) 703 (tab-bar-rename-tab new-name (tab-bar--tab-index-by-name tab-name)))
702 704
@@ -753,7 +755,7 @@ For more information, see the function `tab-bar-list'."
753 (let* ((tabs (delq nil (mapcar (lambda (tab) ; remove current tab 755 (let* ((tabs (delq nil (mapcar (lambda (tab) ; remove current tab
754 (unless (eq (car tab) 'current-tab) 756 (unless (eq (car tab) 'current-tab)
755 tab)) 757 tab))
756 (tab-bar-tabs)))) 758 (funcall tab-bar-tabs-function))))
757 ;; Sort by recency 759 ;; Sort by recency
758 (tabs (sort tabs (lambda (a b) (< (cdr (assq 'time b)) 760 (tabs (sort tabs (lambda (a b) (< (cdr (assq 'time b))
759 (cdr (assq 'time a))))))) 761 (cdr (assq 'time a)))))))
@@ -895,7 +897,7 @@ Then move up one line. Prefix arg means move that many lines."
895 897
896(defun tab-bar-list-delete-from-list (tab) 898(defun tab-bar-list-delete-from-list (tab)
897 "Delete the window configuration from both lists." 899 "Delete the window configuration from both lists."
898 (set-frame-parameter nil 'tabs (delq tab (tab-bar-tabs)))) 900 (set-frame-parameter nil 'tabs (delq tab (funcall tab-bar-tabs-function))))
899 901
900(defun tab-bar-list-execute () 902(defun tab-bar-list-execute ()
901 "Delete window configurations marked with \\<tab-bar-list-mode-map>\\[tab-bar-list-delete] commands." 903 "Delete window configurations marked with \\<tab-bar-list-mode-map>\\[tab-bar-list-delete] commands."