aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2019-10-20 23:54:48 +0300
committerJuri Linkov2019-10-20 23:54:48 +0300
commit5cc1bd5ea1b7e57f36b52b33f2d8b6c42f620d0f (patch)
tree4d1bc919faf6cbddcd6f1d4378577c277754af28
parent987366065b5809f5707b375ce8000664249b8a4f (diff)
downloademacs-5cc1bd5ea1b7e57f36b52b33f2d8b6c42f620d0f.tar.gz
emacs-5cc1bd5ea1b7e57f36b52b33f2d8b6c42f620d0f.zip
* lisp/tab-bar.el: Use autoloaded seq-position.
* lisp/tab-bar.el (tab-bar--current-tab-index) (tab-bar--tab-index, tab-bar--tab-index-by-name): Use seq-position. (tab-bar-select-tab, tab-bar-new-tab, tab-bar-close-tab) (tab-bar-close-other-tabs, tab-bar-rename-tab) (tab-bar-list-execute): Call force-mode-line-update unconditionally independent from tab-bar-mode. (tab-bar-rename-tab, tab-bar-rename-tab-by-name): Use read-from-minibuffer instead of read-string to be able to enter empty string.
-rw-r--r--lisp/tab-bar.el69
1 files changed, 26 insertions, 43 deletions
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index 113202a3b54..098d7057e54 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -445,36 +445,16 @@ Return its existing value or a new value."
445 (explicit-name . ,tab-explicit-name)))) 445 (explicit-name . ,tab-explicit-name))))
446 446
447(defun tab-bar--current-tab-index (&optional tabs) 447(defun tab-bar--current-tab-index (&optional tabs)
448 ;; FIXME: could be replaced with 1-liner using seq-position 448 (seq-position (or tabs (funcall tab-bar-tabs-function))
449 (let ((tabs (or tabs (funcall tab-bar-tabs-function))) 449 'current-tab (lambda (a b) (eq (car a) b))))
450 (i 0))
451 (catch 'done
452 (while tabs
453 (when (eq (car (car tabs)) 'current-tab)
454 (throw 'done i))
455 (setq i (1+ i) tabs (cdr tabs))))))
456 450
457(defun tab-bar--tab-index (tab &optional tabs) 451(defun tab-bar--tab-index (tab &optional tabs)
458 ;; FIXME: could be replaced with 1-liner using seq-position 452 (seq-position (or tabs (funcall tab-bar-tabs-function))
459 (let ((tabs (or tabs (funcall tab-bar-tabs-function))) 453 tab))
460 (i 0))
461 (catch 'done
462 (while tabs
463 (when (eq (car tabs) tab)
464 (throw 'done i))
465 (setq i (1+ i) tabs (cdr tabs))))
466 i))
467 454
468(defun tab-bar--tab-index-by-name (name &optional tabs) 455(defun tab-bar--tab-index-by-name (name &optional tabs)
469 ;; FIXME: could be replaced with 1-liner using seq-position 456 (seq-position (or tabs (funcall tab-bar-tabs-function))
470 (let ((tabs (or tabs (funcall tab-bar-tabs-function))) 457 name (lambda (a b) (equal (cdr (assq 'name a)) b))))
471 (i 0))
472 (catch 'done
473 (while tabs
474 (when (equal (cdr (assq 'name (car tabs))) name)
475 (throw 'done i))
476 (setq i (1+ i) tabs (cdr tabs))))
477 i))
478 458
479 459
480(defun tab-bar-select-tab (&optional arg) 460(defun tab-bar-select-tab (&optional arg)
@@ -513,8 +493,7 @@ to the numeric argument. ARG counts from 1."
513 (setf (nth from-index tabs) from-tab)) 493 (setf (nth from-index tabs) from-tab))
514 (setf (nth to-index tabs) (tab-bar--current-tab (nth to-index tabs)))) 494 (setf (nth to-index tabs) (tab-bar--current-tab (nth to-index tabs))))
515 495
516 (when tab-bar-mode 496 (force-mode-line-update))))
517 (force-mode-line-update)))))
518 497
519(defun tab-bar-switch-to-next-tab (&optional arg) 498(defun tab-bar-switch-to-next-tab (&optional arg)
520 "Switch to ARGth next tab." 499 "Switch to ARGth next tab."
@@ -617,8 +596,9 @@ If `rightmost', create as the last tab."
617 (and (natnump tab-bar-show) 596 (and (natnump tab-bar-show)
618 (> (length tabs) tab-bar-show)))) 597 (> (length tabs) tab-bar-show))))
619 (tab-bar-mode 1)) 598 (tab-bar-mode 1))
620 (if tab-bar-mode 599
621 (force-mode-line-update) 600 (force-mode-line-update)
601 (unless tab-bar-mode
622 (message "Added new tab at %s" tab-bar-new-tab-to)))) 602 (message "Added new tab at %s" tab-bar-new-tab-to))))
623 603
624 604
@@ -664,8 +644,9 @@ TO-INDEX counts from 1."
664 (and (natnump tab-bar-show) 644 (and (natnump tab-bar-show)
665 (<= (length tabs) tab-bar-show))) 645 (<= (length tabs) tab-bar-show)))
666 (tab-bar-mode -1)) 646 (tab-bar-mode -1))
667 (if tab-bar-mode 647
668 (force-mode-line-update) 648 (force-mode-line-update)
649 (unless tab-bar-mode
669 (message "Deleted tab and switched to %s" tab-bar-close-tab-select)))) 650 (message "Deleted tab and switched to %s" tab-bar-close-tab-select))))
670 651
671(defun tab-bar-close-tab-by-name (name) 652(defun tab-bar-close-tab-by-name (name)
@@ -687,8 +668,9 @@ TO-INDEX counts from 1."
687 (and (natnump tab-bar-show) 668 (and (natnump tab-bar-show)
688 (<= 1 tab-bar-show))) 669 (<= 1 tab-bar-show)))
689 (tab-bar-mode -1)) 670 (tab-bar-mode -1))
690 (if tab-bar-mode 671
691 (force-mode-line-update) 672 (force-mode-line-update)
673 (unless tab-bar-mode
692 (message "Deleted all other tabs"))))) 674 (message "Deleted all other tabs")))))
693 675
694 676
@@ -702,8 +684,9 @@ function `tab-bar-tab-name-function'."
702 (let* ((tabs (funcall tab-bar-tabs-function)) 684 (let* ((tabs (funcall tab-bar-tabs-function))
703 (tab-index (or current-prefix-arg (1+ (tab-bar--current-tab-index tabs)))) 685 (tab-index (or current-prefix-arg (1+ (tab-bar--current-tab-index tabs))))
704 (tab-name (cdr (assq 'name (nth (1- tab-index) tabs))))) 686 (tab-name (cdr (assq 'name (nth (1- tab-index) tabs)))))
705 (list (read-string "New name for tab (leave blank for automatic naming): " 687 (list (read-from-minibuffer
706 nil nil tab-name) 688 "New name for tab (leave blank for automatic naming): "
689 nil nil nil nil tab-name)
707 current-prefix-arg))) 690 current-prefix-arg)))
708 (let* ((tabs (funcall tab-bar-tabs-function)) 691 (let* ((tabs (funcall tab-bar-tabs-function))
709 (tab-index (if arg 692 (tab-index (if arg
@@ -716,8 +699,9 @@ function `tab-bar-tab-name-function'."
716 (funcall tab-bar-tab-name-function)))) 699 (funcall tab-bar-tab-name-function))))
717 (setf (cdr (assq 'name tab-to-rename)) tab-new-name 700 (setf (cdr (assq 'name tab-to-rename)) tab-new-name
718 (cdr (assq 'explicit-name tab-to-rename)) tab-explicit-name) 701 (cdr (assq 'explicit-name tab-to-rename)) tab-explicit-name)
719 (if tab-bar-mode 702
720 (force-mode-line-update) 703 (force-mode-line-update)
704 (unless tab-bar-mode
721 (message "Renamed tab to '%s'" tab-new-name)))) 705 (message "Renamed tab to '%s'" tab-new-name))))
722 706
723(defun tab-bar-rename-tab-by-name (tab-name new-name) 707(defun tab-bar-rename-tab-by-name (tab-name new-name)
@@ -729,9 +713,9 @@ function `tab-bar-tab-name-function'."
729 (mapcar (lambda (tab) 713 (mapcar (lambda (tab)
730 (cdr (assq 'name tab))) 714 (cdr (assq 'name tab)))
731 (funcall tab-bar-tabs-function))))) 715 (funcall tab-bar-tabs-function)))))
732 (list tab-name 716 (list tab-name (read-from-minibuffer
733 (read-string "New name for tab (leave blank for automatic naming): " 717 "New name for tab (leave blank for automatic naming): "
734 nil nil tab-name)))) 718 nil nil nil nil tab-name))))
735 (tab-bar-rename-tab new-name (1+ (tab-bar--tab-index-by-name tab-name)))) 719 (tab-bar-rename-tab new-name (1+ (tab-bar--tab-index-by-name tab-name))))
736 720
737 721
@@ -950,8 +934,7 @@ Then move up one line. Prefix arg means move that many lines."
950 (delete-region (point) (progn (forward-line 1) (point)))))))) 934 (delete-region (point) (progn (forward-line 1) (point))))))))
951 (beginning-of-line) 935 (beginning-of-line)
952 (move-to-column tab-bar-list-column) 936 (move-to-column tab-bar-list-column)
953 (when tab-bar-mode 937 (force-mode-line-update))
954 (force-mode-line-update)))
955 938
956(defun tab-bar-list-select () 939(defun tab-bar-list-select ()
957 "Select this line's window configuration. 940 "Select this line's window configuration.