From: Juri Linkov Date: Wed, 21 Apr 2010 00:31:48 +0000 (+0300) Subject: Add switch-to-buffer-other-tab, find-file-other-tab, pop-up-tabs. X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=3c91bc5733c66d1f3a68951589c1e54e9b9c8711;p=emacs.git Add switch-to-buffer-other-tab, find-file-other-tab, pop-up-tabs. Use pop-up-tabs in display-buffer and pop-to-buffer. --- diff --git a/lisp/files.el b/lisp/files.el index c65e1e87b5f..9b27a5be95d 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -1235,6 +1235,31 @@ documentation for additional customization information." 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 @@ -1362,6 +1387,29 @@ expand wildcards (if any) and visit multiple files." (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. diff --git a/lisp/window.el b/lisp/window.el index 41a5d17321f..c2a423f751a 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -808,6 +808,11 @@ that 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 @@ -1144,6 +1149,11 @@ consider all visible or iconified frames." ;; 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)) @@ -1223,8 +1233,11 @@ at the front of the list of recently selected ones." (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)