diff options
| -rw-r--r-- | lisp/tab-bar.el | 56 | ||||
| -rw-r--r-- | lisp/windmove.el | 25 | ||||
| -rw-r--r-- | lisp/window.el | 16 |
3 files changed, 69 insertions, 28 deletions
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el index fac27f41ba9..873f54a27db 100644 --- a/lisp/tab-bar.el +++ b/lisp/tab-bar.el | |||
| @@ -1467,8 +1467,7 @@ This is an action function for buffer display, see Info | |||
| 1467 | node `(elisp) Buffer Display Action Functions'. It should be | 1467 | node `(elisp) Buffer Display Action Functions'. It should be |
| 1468 | called only by `display-buffer' or a function directly or | 1468 | called only by `display-buffer' or a function directly or |
| 1469 | indirectly called by the latter." | 1469 | indirectly called by the latter." |
| 1470 | (let* ((tab-name (alist-get 'tab-name alist)) | 1470 | (let* ((reusable-frames (alist-get 'reusable-frames alist)) |
| 1471 | (reusable-frames (alist-get 'reusable-frames alist)) | ||
| 1472 | (reusable-tab (when reusable-frames | 1471 | (reusable-tab (when reusable-frames |
| 1473 | (tab-bar-get-buffer-tab buffer reusable-frames)))) | 1472 | (tab-bar-get-buffer-tab buffer reusable-frames)))) |
| 1474 | (if reusable-tab | 1473 | (if reusable-tab |
| @@ -1480,26 +1479,55 @@ indirectly called by the latter." | |||
| 1480 | (tab-bar-select-tab (1+ index))) | 1479 | (tab-bar-select-tab (1+ index))) |
| 1481 | (when (get-buffer-window buffer frame) | 1480 | (when (get-buffer-window buffer frame) |
| 1482 | (select-window (get-buffer-window buffer frame)))) | 1481 | (select-window (get-buffer-window buffer frame)))) |
| 1482 | (let ((tab-name (alist-get 'tab-name alist))) | ||
| 1483 | (when (functionp tab-name) | ||
| 1484 | (setq tab-name (funcall tab-name buffer alist))) | ||
| 1485 | (if tab-name | ||
| 1486 | (let ((tab-index (tab-bar--tab-index-by-name tab-name))) | ||
| 1487 | (if tab-index | ||
| 1488 | (progn | ||
| 1489 | (tab-bar-select-tab (1+ tab-index)) | ||
| 1490 | (when (get-buffer-window buffer) | ||
| 1491 | (select-window (get-buffer-window buffer)))) | ||
| 1492 | (display-buffer-in-new-tab buffer alist))) | ||
| 1493 | (display-buffer-in-new-tab buffer alist)))))) | ||
| 1494 | |||
| 1495 | (defun display-buffer-in-new-tab (buffer alist) | ||
| 1496 | "Display BUFFER in a new tab. | ||
| 1497 | ALIST is an association list of action symbols and values. See | ||
| 1498 | Info node `(elisp) Buffer Display Action Alists' for details of | ||
| 1499 | such alists. | ||
| 1500 | |||
| 1501 | Like `display-buffer-in-tab', but always creates a new tab unconditionally, | ||
| 1502 | without checking if a suitable tab already exists. | ||
| 1503 | |||
| 1504 | If ALIST contains a `tab-name' entry, it creates a new tab with that name | ||
| 1505 | and displays BUFFER in a new tab. The `tab-name' entry can be a function, | ||
| 1506 | then it is called with two arguments: BUFFER and ALIST, and should return | ||
| 1507 | the tab name. When a `tab-name' entry is omitted, create a new tab without | ||
| 1508 | an explicit name. | ||
| 1509 | |||
| 1510 | This is an action function for buffer display, see Info | ||
| 1511 | node `(elisp) Buffer Display Action Functions'. It should be | ||
| 1512 | called only by `display-buffer' or a function directly or | ||
| 1513 | indirectly called by the latter." | ||
| 1514 | (let ((tab-bar-new-tab-choice t)) | ||
| 1515 | (tab-bar-new-tab) | ||
| 1516 | (let ((tab-name (alist-get 'tab-name alist))) | ||
| 1483 | (when (functionp tab-name) | 1517 | (when (functionp tab-name) |
| 1484 | (setq tab-name (funcall tab-name buffer alist))) | 1518 | (setq tab-name (funcall tab-name buffer alist))) |
| 1485 | (if tab-name | 1519 | (when tab-name |
| 1486 | (let ((tab-index (tab-bar--tab-index-by-name tab-name))) | 1520 | (tab-bar-rename-tab tab-name))) |
| 1487 | (if tab-index | 1521 | (window--display-buffer buffer (selected-window) 'tab alist))) |
| 1488 | (tab-bar-select-tab (1+ tab-index)) | ||
| 1489 | (let ((tab-bar-new-tab-choice t)) | ||
| 1490 | (tab-bar-new-tab) | ||
| 1491 | (tab-bar-rename-tab tab-name)))) | ||
| 1492 | (let ((tab-bar-new-tab-choice t)) | ||
| 1493 | (tab-bar-new-tab)))))) | ||
| 1494 | 1522 | ||
| 1495 | (defun switch-to-buffer-other-tab (buffer-or-name &optional norecord) | 1523 | (defun switch-to-buffer-other-tab (buffer-or-name &optional norecord) |
| 1496 | "Switch to buffer BUFFER-OR-NAME in another tab. | 1524 | "Switch to buffer BUFFER-OR-NAME in another tab. |
| 1497 | Like \\[switch-to-buffer-other-frame] (which see), but creates a new tab." | 1525 | Like \\[switch-to-buffer-other-frame] (which see), but creates a new tab." |
| 1498 | (interactive | 1526 | (interactive |
| 1499 | (list (read-buffer-to-switch "Switch to buffer in other tab: "))) | 1527 | (list (read-buffer-to-switch "Switch to buffer in other tab: "))) |
| 1500 | (display-buffer buffer-or-name '((display-buffer-in-tab | 1528 | (display-buffer buffer-or-name '((display-buffer-in-tab) |
| 1501 | display-buffer-same-window) | 1529 | (inhibit-same-window . nil) |
| 1502 | (inhibit-same-window . nil)) | 1530 | (reusable-frames . t)) |
| 1503 | norecord)) | 1531 | norecord)) |
| 1504 | 1532 | ||
| 1505 | (defun find-file-other-tab (filename &optional wildcards) | 1533 | (defun find-file-other-tab (filename &optional wildcards) |
diff --git a/lisp/windmove.el b/lisp/windmove.el index 6e62e161548..40adb49e20f 100644 --- a/lisp/windmove.el +++ b/lisp/windmove.el | |||
| @@ -467,18 +467,19 @@ When `switch-to-buffer-obey-display-actions' is non-nil, | |||
| 467 | (minibuffer-depth (minibuffer-depth)) | 467 | (minibuffer-depth (minibuffer-depth)) |
| 468 | (action (lambda (buffer alist) | 468 | (action (lambda (buffer alist) |
| 469 | (unless (> (minibuffer-depth) minibuffer-depth) | 469 | (unless (> (minibuffer-depth) minibuffer-depth) |
| 470 | (let ((window (cond | 470 | (let* ((type 'reuse) |
| 471 | ((eq dir 'new-tab) | 471 | (window (cond |
| 472 | (let ((tab-bar-new-tab-choice t)) | 472 | ((eq dir 'new-tab) |
| 473 | (tab-bar-new-tab)) | 473 | (let ((tab-bar-new-tab-choice t)) |
| 474 | (selected-window)) | 474 | (tab-bar-new-tab)) |
| 475 | ((eq dir 'same-window) | 475 | (setq type 'tab) |
| 476 | (selected-window)) | 476 | (selected-window)) |
| 477 | (t (window-in-direction | 477 | ((eq dir 'same-window) |
| 478 | dir nil nil | 478 | (selected-window)) |
| 479 | (and arg (prefix-numeric-value arg)) | 479 | (t (window-in-direction |
| 480 | windmove-wrap-around)))) | 480 | dir nil nil |
| 481 | (type 'reuse)) | 481 | (and arg (prefix-numeric-value arg)) |
| 482 | windmove-wrap-around))))) | ||
| 482 | (unless window | 483 | (unless window |
| 483 | (setq window (split-window nil nil dir) type 'window)) | 484 | (setq window (split-window nil nil dir) type 'window)) |
| 484 | (setq new-window (window--display-buffer buffer window | 485 | (setq new-window (window--display-buffer buffer window |
diff --git a/lisp/window.el b/lisp/window.el index 40c4bf5ad47..bd825c09e16 100644 --- a/lisp/window.el +++ b/lisp/window.el | |||
| @@ -5009,6 +5009,13 @@ nil means to not handle the buffer in a particular way. This | |||
| 5009 | quad entry) | 5009 | quad entry) |
| 5010 | (cond | 5010 | (cond |
| 5011 | ((and (not prev-buffer) | 5011 | ((and (not prev-buffer) |
| 5012 | (eq (nth 1 quit-restore) 'tab) | ||
| 5013 | (eq (nth 3 quit-restore) buffer)) | ||
| 5014 | (tab-bar-close-tab) | ||
| 5015 | ;; If the previously selected window is still alive, select it. | ||
| 5016 | (when (window-live-p (nth 2 quit-restore)) | ||
| 5017 | (select-window (nth 2 quit-restore)))) | ||
| 5018 | ((and (not prev-buffer) | ||
| 5012 | (or (eq (nth 1 quit-restore) 'frame) | 5019 | (or (eq (nth 1 quit-restore) 'frame) |
| 5013 | (and (eq (nth 1 quit-restore) 'window) | 5020 | (and (eq (nth 1 quit-restore) 'window) |
| 5014 | ;; If the window has been created on an existing | 5021 | ;; If the window has been created on an existing |
| @@ -6367,7 +6374,12 @@ fourth element is BUFFER." | |||
| 6367 | ;; WINDOW has been created on a new frame. | 6374 | ;; WINDOW has been created on a new frame. |
| 6368 | (set-window-parameter | 6375 | (set-window-parameter |
| 6369 | window 'quit-restore | 6376 | window 'quit-restore |
| 6370 | (list 'frame 'frame (selected-window) buffer))))) | 6377 | (list 'frame 'frame (selected-window) buffer))) |
| 6378 | ((eq type 'tab) | ||
| 6379 | ;; WINDOW has been created on a new tab. | ||
| 6380 | (set-window-parameter | ||
| 6381 | window 'quit-restore | ||
| 6382 | (list 'tab 'tab (selected-window) buffer))))) | ||
| 6371 | 6383 | ||
| 6372 | (defcustom display-buffer-function nil | 6384 | (defcustom display-buffer-function nil |
| 6373 | "If non-nil, function to call to handle `display-buffer'. | 6385 | "If non-nil, function to call to handle `display-buffer'. |
| @@ -7034,7 +7046,7 @@ Return WINDOW if BUFFER and WINDOW are live." | |||
| 7034 | ;; use that. | 7046 | ;; use that. |
| 7035 | (display-buffer-mark-dedicated | 7047 | (display-buffer-mark-dedicated |
| 7036 | (set-window-dedicated-p window display-buffer-mark-dedicated)))) | 7048 | (set-window-dedicated-p window display-buffer-mark-dedicated)))) |
| 7037 | (when (memq type '(window frame)) | 7049 | (when (memq type '(window frame tab)) |
| 7038 | (set-window-prev-buffers window nil)) | 7050 | (set-window-prev-buffers window nil)) |
| 7039 | (let ((quit-restore (window-parameter window 'quit-restore)) | 7051 | (let ((quit-restore (window-parameter window 'quit-restore)) |
| 7040 | (height (cdr (assq 'window-height alist))) | 7052 | (height (cdr (assq 'window-height alist))) |