same-window-buffer-names same-window-regexps)
(pop-to-buffer buffer-or-name t norecord)))
+(defun switch-to-buffer-other-tab (buffer-or-name &optional norecord)
+ "Select the buffer specified by BUFFER-OR-NAME in another tab.
+BUFFER-OR-NAME may be a buffer, a string \(a buffer name), or
+nil. Return the buffer switched to.
+
+If called interactively, prompt for the buffer name using the
+minibuffer. The variable `confirm-nonexistent-file-or-buffer'
+determines whether to request confirmation before creating a new
+buffer.
+
+If BUFFER-OR-NAME is a string and does not identify an existing
+buffer, create a new buffer with that name. If BUFFER-OR-NAME is
+nil, switch to the buffer returned by `other-buffer'.
+
+Optional second argument NORECORD non-nil means do not put this
+buffer at the front of the list of recently selected ones.
+
+This uses the function `display-buffer' as a subroutine; see its
+documentation for additional customization information."
+ (interactive
+ (list (read-buffer-to-switch "Switch to buffer in other tab: ")))
+ (let ((pop-up-tabs t)
+ same-tab-buffer-names same-tab-regexps)
+ (pop-to-buffer buffer-or-name t norecord)))
+
(defun switch-to-buffer-other-frame (buffer-or-name &optional norecord)
"Switch to buffer BUFFER-OR-NAME in another frame.
BUFFER-OR-NAME may be a buffer, a string \(a buffer name), or
(mapcar 'switch-to-buffer (cdr value))))
(switch-to-buffer-other-window value))))
+(defun find-file-other-tab (filename &optional wildcards)
+ "Edit file FILENAME, in another tab.
+
+Like \\[find-file] (which see), but creates a new tab.
+See the function `display-buffer'.
+
+Interactively, the default if you just type RET is the current directory,
+but the visited file name is available through the minibuffer history:
+type M-n to pull it into the minibuffer.
+
+Interactively, or if WILDCARDS is non-nil in a call from Lisp,
+expand wildcards (if any) and visit multiple files."
+ (interactive
+ (find-file-read-args "Find file in other tab: "
+ (confirm-nonexistent-file-or-buffer)))
+ (let ((value (find-file-noselect filename nil nil wildcards)))
+ (if (listp value)
+ (progn
+ (setq value (nreverse value))
+ (cons (switch-to-buffer-other-tab (car value))
+ (mapcar 'switch-to-buffer (cdr value))))
+ (switch-to-buffer-other-tab value))))
+
(defun find-file-other-frame (filename &optional wildcards)
"Edit file FILENAME, in another frame.
:type 'boolean
:group 'windows)
+(defcustom pop-up-tabs nil
+ "Non-nil means `display-buffer' should make a new tab."
+ :type 'boolean
+ :group 'tabs)
+
(defcustom split-window-preferred-function 'split-window-sensibly
"Function called by `display-buffer' routines to split a window.
This function is called with a window as single argument and is
;; We want or need a new frame.
(let ((win (frame-selected-window (funcall pop-up-frame-function))))
(window--display-buffer-2 buffer win display-buffer-mark-dedicated)))
+ (pop-up-tabs
+ ;; Make a new tab.
+ (select-tab (make-tab))
+ (window--display-buffer-2 buffer (selected-window)
+ display-buffer-mark-dedicated))
((and pop-up-windows
;; Make a new window.
(or (not (frame-parameter frame-to-use 'unsplittable))
(old-window (selected-window))
(old-frame (selected-frame))
new-window new-frame)
- (set-buffer buffer)
+ (unless pop-up-tabs
+ (set-buffer buffer))
(setq new-window (display-buffer buffer other-window))
+ (when pop-up-tabs
+ (set-buffer buffer))
(unless (eq new-window old-window)
;; `display-buffer' has chosen another window, select it.
(select-window new-window norecord)