emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 8ad221c: * lisp/tab-bar.el (tab-bar--current-tab-find): New funct


From: Juri Linkov
Subject: master 8ad221c: * lisp/tab-bar.el (tab-bar--current-tab-find): New function.
Date: Thu, 11 Mar 2021 14:05:35 -0500 (EST)

branch: master
commit 8ad221cdf4337a3c4e2d270e09973b4e67a4b4a2
Author: Juri Linkov <juri@linkov.net>
Commit: Juri Linkov <juri@linkov.net>

    * lisp/tab-bar.el (tab-bar--current-tab-find): New function.
    
    (tab-bar-close-other-tabs, tab-bar-close-group-tabs): Use it.
    (tab-bar--history-pre-change): Rename from
    'tab-bar-history--pre-change' to follow naming convention.
    (tab-bar-history-mode): Use renamed 'tab-bar--history-pre-change'.
---
 lisp/tab-bar.el | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index 66f8cca..29465aa 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -681,6 +681,10 @@ on the tab bar instead."
       (explicit-name . ,tab-explicit-name)
       ,@(if tab-group `((group . ,tab-group))))))
 
+(defun tab-bar--current-tab-find (&optional tabs frame)
+  (seq-find (lambda (tab) (eq (car tab) 'current-tab))
+            (or tabs (funcall tab-bar-tabs-function frame))))
+
 (defun tab-bar--current-tab-index (&optional tabs frame)
   (seq-position (or tabs (funcall tab-bar-tabs-function frame))
                 'current-tab (lambda (a b) (eq (car a) b))))
@@ -1148,8 +1152,7 @@ for the last tab on a frame is determined by
   "Close all tabs on the selected frame, except the selected one."
   (interactive)
   (let* ((tabs (funcall tab-bar-tabs-function))
-         (current-index (tab-bar--current-tab-index tabs))
-         (current-tab (and current-index (nth current-index tabs)))
+         (current-tab (tab-bar--current-tab-find tabs))
          (index 0))
     (when current-tab
       (dolist (tab tabs)
@@ -1284,8 +1287,7 @@ If GROUP-NAME is the empty string, then remove the tab 
from any group."
   "Close all tabs that belong to GROUP-NAME on the selected frame."
   (interactive
    (let* ((tabs (funcall tab-bar-tabs-function))
-          (tab-index (1+ (tab-bar--current-tab-index tabs)))
-          (group-name (alist-get 'group (nth (1- tab-index) tabs))))
+          (group-name (alist-get 'group (tab-bar--current-tab-find tabs))))
      (list (completing-read
             "Close all tabs with group name: "
             (delete-dups (delq nil (cons group-name
@@ -1300,8 +1302,7 @@ If GROUP-NAME is the empty string, then remove the tab 
from any group."
     (tab-bar-close-other-tabs)
 
     (let* ((tabs (funcall tab-bar-tabs-function))
-           (current-index (tab-bar--current-tab-index tabs))
-           (current-tab (and current-index (nth current-index tabs))))
+           (current-tab (tab-bar--current-tab-find tabs)))
       (when (and current-tab (equal (alist-get 'group current-tab)
                                     close-group))
         (tab-bar-close-tab)))))
@@ -1327,7 +1328,7 @@ If GROUP-NAME is the empty string, then remove the tab 
from any group."
 (defvar tab-bar-history-old-minibuffer-depth 0
   "Minibuffer depth before the current command.")
 
-(defun tab-bar-history--pre-change ()
+(defun tab-bar--history-pre-change ()
   (setq tab-bar-history-old-minibuffer-depth (minibuffer-depth))
   ;; Store wc before possibly entering the minibuffer
   (when (zerop tab-bar-history-old-minibuffer-depth)
@@ -1410,9 +1411,9 @@ and can restore them."
                                                 :ascent center))
                                tab-bar-forward-button))
 
-        (add-hook 'pre-command-hook 'tab-bar-history--pre-change)
+        (add-hook 'pre-command-hook 'tab-bar--history-pre-change)
         (add-hook 'window-configuration-change-hook 'tab-bar--history-change))
-    (remove-hook 'pre-command-hook 'tab-bar-history--pre-change)
+    (remove-hook 'pre-command-hook 'tab-bar--history-pre-change)
     (remove-hook 'window-configuration-change-hook 'tab-bar--history-change)))
 
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]