summaryrefslogtreecommitdiff
path: root/lisp/tab-bar.el
diff options
context:
space:
mode:
authorJuri Linkov <juri@linkov.net>2021-09-12 19:10:02 +0300
committerJuri Linkov <juri@linkov.net>2021-09-12 19:10:02 +0300
commit64c5cd5a8c30779a32bbb676c892c120b17fd35f (patch)
tree3111b5e77cde2b31c806871218c82f76b25d332f /lisp/tab-bar.el
parent8f3199788beceb6c513809a11e6f99b66b8feb5c (diff)
downloademacs-64c5cd5a8c30779a32bbb676c892c120b17fd35f.tar.gz
emacs-64c5cd5a8c30779a32bbb676c892c120b17fd35f.tar.bz2
emacs-64c5cd5a8c30779a32bbb676c892c120b17fd35f.zip
* lisp/tab-bar.el: Improve logic of 'ignore-current-tab'.
* lisp/tab-bar.el (tab-bar-get-buffer-tab): Prefer the current tab when 'ignore-current-tab' is nil. (display-buffer-in-tab): Use alist entry 'ignore-current-tab' as the third arg of 'tab-bar-get-buffer-tab'. Improve docstring. Suggested by Feng Shu <tumashu@163.com> https://lists.gnu.org/archive/html/emacs-devel/2021-09/msg00955.html
Diffstat (limited to 'lisp/tab-bar.el')
-rw-r--r--lisp/tab-bar.el36
1 files changed, 25 insertions, 11 deletions
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index ab6595e45e8..e30a5c44119 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -1917,11 +1917,12 @@ The optional argument ALL-FRAMES specifies the frames to consider:
- A frame means consider all tabs on that frame only.
-Any other value of ALL-FRAMES means consider all tabs on the
+- Any other value of ALL-FRAMES means consider all tabs on the
selected frame and no others.
When the optional argument IGNORE-CURRENT-TAB is non-nil,
-don't take into account the buffers in the currently selected tab."
+don't take into account the buffers in the currently selected tab.
+Otherwise, prefer buffers of the current tab."
(let ((buffer (if buffer-or-name
(get-buffer buffer-or-name)
(current-buffer))))
@@ -1931,8 +1932,7 @@ don't take into account the buffers in the currently selected tab."
(seq-some
(lambda (tab)
(when (if (eq (car tab) 'current-tab)
- (unless ignore-current-tab
- (get-buffer-window buffer frame))
+ (get-buffer-window buffer frame)
(let* ((state (alist-get 'ws tab))
(buffers (when state
(window-state-buffers state))))
@@ -1943,7 +1943,14 @@ don't take into account the buffers in the currently selected tab."
(member (buffer-name buffer) buffers))))
(append tab `((index . ,(tab-bar--tab-index tab nil frame))
(frame . ,frame)))))
- (funcall tab-bar-tabs-function frame)))
+ (let* ((tabs (funcall tab-bar-tabs-function frame))
+ (current-tab (tab-bar--current-tab-find tabs)))
+ (seq-remove (lambda (tab) (eq (car tab) 'current-tab)) tabs)
+ (if ignore-current-tab
+ ;; Use tabs without current-tab.
+ tabs
+ ;; Make sure current-tab is at the beginning of tabs.
+ (cons current-tab tabs)))))
(tab-bar--reusable-frames all-frames)))))
(defun display-buffer-in-tab (buffer alist)
@@ -1963,19 +1970,26 @@ The ALIST entry `tab-group' (string or function) defines the tab group.
If ALIST contains a `reusable-frames' entry, its value determines
which frames to search for a reusable tab:
- nil -- the selected frame (actually the last non-minibuffer frame)
- A frame -- just that frame
- `visible' -- all visible frames
- 0 -- all frames on the current terminal
- t -- all frames.
+ nil -- do not reuse any frames;
+ a frame -- just that frame;
+ `visible' -- all visible frames;
+ 0 -- all frames on the current terminal;
+ t -- all frames;
+ other non-nil values -- use the selected frame.
+
+If ALIST contains a non-nil `ignore-current-tab' entry, then the buffers
+of the current tab are skipped when searching for a reusable tab.
+Otherwise, prefer buffers of the current tab.
This is an action function for buffer display, see Info
node `(elisp) Buffer Display Action Functions'. It should be
called only by `display-buffer' or a function directly or
indirectly called by the latter."
(let* ((reusable-frames (alist-get 'reusable-frames alist))
+ (ignore-current-tab (alist-get 'ignore-current-tab alist))
(reusable-tab (when reusable-frames
- (tab-bar-get-buffer-tab buffer reusable-frames))))
+ (tab-bar-get-buffer-tab buffer reusable-frames
+ ignore-current-tab))))
(if reusable-tab
(let* ((frame (alist-get 'frame reusable-tab))
(index (alist-get 'index reusable-tab)))