

index 0c2509e1cd..7bb6142395 100644

--- a/

+++ b/ diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texiindex 0c2509e1cd..7bb6142395 100644--- a/ doc/emacs/custom.texi +++ b/ doc/emacs/custom.texi @@ -2150,6 +2150,10 @@ The mouse was in a vertical scroll bar. (This is the only kind of scroll bar Emacs currently supports.) @item menu-bar The mouse was in the menu bar. +@item tab-bar +The mouse was in a tab bar. +@item tab-line +The mouse was in a tab line. @item header-line The mouse was in a header line. @ignore

index 6fc99bd271..84363d0f0d 100644

--- a/

+++ b/ diff --git a/doc/emacs/display.texi b/doc/emacs/display.texiindex 6fc99bd271..84363d0f0d 100644--- a/ doc/emacs/display.texi +++ b/ doc/emacs/display.texi @@ -722,6 +722,10 @@ Similar to @code{highlight} and @code{mode-line-highlight}, but used for mouse-sensitive portions of text on header lines. This is a separate face because the @code{header-line} face might be customized in a way that does not interact well with @code{highlight}. +@item tab-line +@cindex @code{tab-line} face +Similar to @code{mode-line} for a window's tab line, which appears +at the top of a window with tabs representing window buffers. @item vertical-border @cindex @code{vertical-border} face This face is used for the vertical divider between windows on text @@ -763,6 +767,8 @@ This face determines the visual appearance of the scroll bar. @xref{Scroll Bars}. @item tool-bar This face determines the color of tool bar icons. @xref{Tool Bars}. +@item tab-bar +This face determines the color of tab bar icons. @xref{Tab Bars}. @item menu @cindex menu bar appearance @cindex @code{menu} face, no effect if customized

index 17aaaea736..28a0f562f8 100644

--- a/

+++ b/ diff --git a/doc/emacs/emacs.texi b/doc/emacs/emacs.texiindex 17aaaea736..28a0f562f8 100644--- a/ doc/emacs/emacs.texi +++ b/ doc/emacs/emacs.texi @@ -540,6 +540,7 @@ Frames and Graphical Displays * Drag and Drop:: Using drag and drop to open files and insert text. * Menu Bars:: Enabling and disabling the menu bar. * Tool Bars:: Enabling and disabling the tool bar. +* Tab Bars:: Enabling and disabling the tab bar. * Dialog Boxes:: Controlling use of dialog boxes. * Tooltips:: Displaying information at the current mouse position. * Mouse Avoidance:: Preventing the mouse pointer from obscuring text.

index 367ac43a0a..0003881fad 100644

--- a/

+++ b/ diff --git a/doc/emacs/frames.texi b/doc/emacs/frames.texiindex 367ac43a0a..0003881fad 100644--- a/ doc/emacs/frames.texi +++ b/ doc/emacs/frames.texi @@ -58,6 +58,7 @@ for doing so on MS-DOS). Menus are supported on all text terminals. * Drag and Drop:: Using drag and drop to open files and insert text. * Menu Bars:: Enabling and disabling the menu bar. * Tool Bars:: Enabling and disabling the tool bar. +* Tab Bars:: Enabling and disabling the tab bar. * Dialog Boxes:: Controlling use of dialog boxes. * Tooltips:: Displaying information at the current mouse position. * Mouse Avoidance:: Preventing the mouse pointer from obscuring text. @@ -1214,6 +1215,41 @@ Parameters,,, elisp, The Emacs Lisp Reference Manual}. On macOS the tool bar is hidden when the frame is put into fullscreen, but can be displayed by moving the mouse pointer to the top of the screen. +@node Tab Bars +@section Tab Bars +@cindex Tab Bar mode +@cindex mode, Tab Bar +@cindex tabs, tabbar + + On graphical displays and on text terminals, Emacs puts a @dfn{tab bar} +at the top of each frame, just below the menu bar. This is a row of +tabs which you can click on with the mouse to switch window configurations. + + Each tab on the tab bar represents a named persistent window +configuration. Its name is composed from the names of buffers +visible in windows of the window configuration. Clicking on the +tab name switches the current window configuration to the previously +used configuration of windows and buffers. + + If you are using the desktop library to save and restore your +sessions, the tabs from the tab bar are recorded in the desktop file, +together with their associated window configurations. + +@findex tab-bar-mode +@vindex tab-bar-mode + To toggle the use of tab bars, type @kbd{M-x tab-bar-mode}. This +command applies to all frames, including frames yet to be created. To +control the use of tab bars at startup, customize the variable +@code{tab-bar-mode}. + +@vindex tab-bar-new-tab-choice +@cindex Tab Bar new tab + By default, Emacs follows the same behavior as when creating frames, +to start a new tab with the current buffer, i.e. the buffer +that was current before calling the command that adds a new tab. +To start a new tab with other buffers, customize the variable +@code{tab-bar-new-tab-choice}. + @node Dialog Boxes @section Using Dialog Boxes @cindex dialog boxes

index ad16d72ddb..30ddffab69 100644

--- a/

+++ b/ diff --git a/doc/emacs/glossary.texi b/doc/emacs/glossary.texiindex ad16d72ddb..30ddffab69 100644--- a/ doc/emacs/glossary.texi +++ b/ doc/emacs/glossary.texi @@ -1360,6 +1360,15 @@ your buffers, unsaved edits, undo history, etc. @xref{Exiting}. @key{TAB} is the tab character. In Emacs it is typically used for indentation or completion. +@item Tab Bar +The tab bar is a row of tabs at the top of an Emacs frame. +Clicking on one of these tabs switches named persistent window +configurations. @xref{Tab Bars}. + +@item Tab Line +The tab line is a line of tabs at the top of an Emacs window. +Clicking on one of these tabs switches window buffers. + @anchor{Glossary---Tags Table} @item Tags Table A tags table is a file that serves as an index to the function

index e01dfa2677..64034d7186 100644

--- a/

+++ b/ diff --git a/doc/emacs/modes.texi b/doc/emacs/modes.texiindex e01dfa2677..64034d7186 100644--- a/ doc/emacs/modes.texi +++ b/ doc/emacs/modes.texi @@ -296,6 +296,12 @@ but the tool bar is only displayed on graphical terminals. @xref{Tool Bars}. @item +Tab Bar mode gives each frame a tab bar. @xref{Tab Bars}. + +@item +Tab Line mode gives each window a tab line. + +@item Transient Mark mode highlights the region, and makes many Emacs commands operate on the region when the mark is active. It is enabled by default. @xref{Mark}.

index 1fd56d0284..a351917b85 100644

--- a/

+++ b/ diff --git a/doc/lispref/commands.texi b/doc/lispref/commands.texiindex 1fd56d0284..a351917b85 100644--- a/ doc/lispref/commands.texi +++ b/ doc/lispref/commands.texi @@ -1348,8 +1348,8 @@ button. @xref{Repeat Events}. @var{position} slot of a click event, you should typically use the functions documented in @ref{Accessing Mouse}. The explicit format of the list depends on where the click occurred. For clicks in the text -area, mode line, header line, or in the fringe or marginal areas, the -mouse position list has the form +area, mode line, header line, tab line, or in the fringe or marginal +areas, the mouse position list has the form @example (@var{window} @var{pos-or-area} (@var{x} . @var{y}) @var{timestamp} @@ -1368,8 +1368,9 @@ The window in which the click occurred. The buffer position of the character clicked on in the text area; or, if the click was outside the text area, the window area where it occurred. It is one of the symbols @code{mode-line}, -@code{header-line}, @code{vertical-line}, @code{left-margin}, -@code{right-margin}, @code{left-fringe}, or @code{right-fringe}. +@code{header-line}, @code{tab-line}, @code{vertical-line}, +@code{left-margin}, @code{right-margin}, @code{left-fringe}, or +@code{right-fringe}. In one special case, @var{pos-or-area} is a list containing a symbol (one of the symbols listed above) instead of just the symbol. This @@ -1380,12 +1381,12 @@ by Emacs. @xref{Key Sequence Input}. The relative pixel coordinates of the click. For clicks in the text area of a window, the coordinate origin @code{(0 . 0)} is taken to be the top left corner of the text area. @xref{Window Sizes}. For -clicks in a mode line or header line, the coordinate origin is the top -left corner of the window itself. For fringes, margins, and the -vertical border, @var{x} does not have meaningful data. For fringes -and margins, @var{y} is relative to the bottom edge of the header -line. In all cases, the @var{x} and @var{y} coordinates increase -rightward and downward respectively. +clicks in a mode line, header line or tab line, the coordinate origin +is the top left corner of the window itself. For fringes, margins, +and the vertical border, @var{x} does not have meaningful data. +For fringes and margins, @var{y} is relative to the bottom edge of the +header line. In all cases, the @var{x} and @var{y} coordinates +increase rightward and downward respectively. @item @var{timestamp} The time at which the event occurred, as an integer number of @@ -1407,17 +1408,18 @@ The position in the string where the click occurred. @item @var{text-pos} For clicks on a marginal area or on a fringe, this is the buffer position of the first visible character in the corresponding line in -the window. For clicks on the mode line or the header line, this is -@code{nil}. For other events, it is the buffer position closest to -the click. +the window. For clicks on the mode line, the header line or the tab +line, this is @code{nil}. For other events, it is the buffer position +closest to the click. @item @var{col}, @var{row} These are the actual column and row coordinate numbers of the glyph under the @var{x}, @var{y} position. If @var{x} lies beyond the last column of actual text on its line, @var{col} is reported by adding -fictional extra columns that have the default character width. Row 0 -is taken to be the header line if the window has one, or the topmost -row of the text area otherwise. Column 0 is taken to be the leftmost +fictional extra columns that have the default character width. +Row 0 is taken to be the header line if the window has one, or Row 1 +if the window also has the tab line, or the topmost row of +the text area otherwise. Column 0 is taken to be the leftmost column of the text area for clicks on a window text area, or the leftmost mode line or header line column for clicks there. For clicks on fringes or vertical borders, these have no meaningful data. For @@ -2094,7 +2096,8 @@ computed values.) Note that @var{row} is counted from the top of the text area. If the window given by @var{position} possesses a header line (@pxref{Header -Lines}), it is @emph{not} included in the @var{row} count. +Lines}) or a tab line, they are @emph{not} included in the @var{row} +count. @end defun @defun posn-actual-col-row position @@ -2452,12 +2455,14 @@ button-down events entirely. It also reshuffles focus events and miscellaneous window events so that they never appear in a key sequence with any other events. +@cindex @code{tab-line} prefix key @cindex @code{header-line} prefix key @cindex @code{mode-line} prefix key @cindex @code{vertical-line} prefix key @cindex @code{horizontal-scroll-bar} prefix key @cindex @code{vertical-scroll-bar} prefix key @cindex @code{menu-bar} prefix key +@cindex @code{tab-bar} prefix key @cindex mouse events, in special parts of frame When mouse events occur in special parts of a window, such as a mode line or a scroll bar, the event type shows nothing special---it is the @@ -2465,8 +2470,8 @@ same symbol that would normally represent that combination of mouse button and modifier keys. The information about the window part is kept elsewhere in the event---in the coordinates. But @code{read-key-sequence} translates this information into imaginary -prefix keys, all of which are symbols: @code{header-line}, -@code{horizontal-scroll-bar}, @code{menu-bar}, @code{mode-line}, +prefix keys, all of which are symbols: @code{tab-line}, @code{header-line}, +@code{horizontal-scroll-bar}, @code{menu-bar}, @code{tab-bar}, @code{mode-line}, @code{vertical-line}, and @code{vertical-scroll-bar}. You can define meanings for mouse clicks in special window parts by defining key sequences using these imaginary prefix keys.

index 64b24f712a..494bf0d3f7 100644

--- a/

+++ b/ diff --git a/doc/lispref/display.texi b/doc/lispref/display.texiindex 64b24f712a..494bf0d3f7 100644--- a/ doc/lispref/display.texi +++ b/ doc/lispref/display.texi @@ -2944,6 +2944,7 @@ If the text lies within the mode line of the selected window, Emacs applies the @code{mode-line} face. For the mode line of a non-selected window, Emacs applies the @code{mode-line-inactive} face. For a header line, Emacs applies the @code{header-line} face. +For a tab line, Emacs applies the @code{tab-line} face. @item If the text comes from an overlay string via @code{before-string} or

index 39d3960c9a..f05a6db176 100644

--- a/

+++ b/ diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texiindex 39d3960c9a..f05a6db176 100644--- a/ doc/lispref/windows.texi +++ b/ doc/lispref/windows.texi @@ -5558,6 +5558,9 @@ The coordinates are in the mode line of @var{window}. @item header-line The coordinates are in the header line of @var{window}. +@item tab-line +The coordinates are in the tab line of @var{window}. + @item right-divider The coordinates are in the divider separating @var{window} from a window on the right. @@ -6115,6 +6118,15 @@ to suppress display of a header line for this window. Display and contents of the header line on other windows showing this buffer are not affected. +@item tab-line-format +@vindex tab-line-format@r{, a window parameter} +This parameter replaces the value of the buffer-local variable +@code{tab-line-format} (@pxref{Mode Line Basics}) of this window's +buffer whenever this window is displayed. The symbol @code{none} means +to suppress display of a tab line for this window. Display and +contents of the tab line on other windows showing this buffer are not +affected. + @item min-margins @vindex min-margins@r{, a window parameter} The value of this parameter is a cons cell whose @sc{car} and

index 04e2657e7c..00a01999a7 100644

--- a/

+++ b/ diff --git a/etc/NEWS b/etc/NEWSindex 04e2657e7c..00a01999a7 100644--- a/ etc/NEWS +++ b/ etc/NEWS @@ -2030,6 +2030,34 @@ file-local variable, you may need to update the value. * New Modes and Packages in Emacs 27.1 +** 'tab-bar-mode' enables the tab-bar at the top of each frame, +to switch named persistent window configurations in it using tabs. +New tab-based keybindings (similar to frame-based commands): +'C-x 6 2' creates a new tab; +'C-x 6 0' deletes the current tab; +'C-x 6 b' switches to buffer in another tab; +'C-x 6 f' and 'C-x 6 C-f' edit file in another tab; +'C-TAB' switches to the next tab; +'S-C-TAB' switches to the previous tab. + +Also it's possible to switch named persistent window configurations +without having graphical access to the tab-bar, even on a tty +or when 'tab-bar-mode' is disabled, with these commands: +'tab-new' creates a new window configuration; +'tab-close' deletes the current window configuration; +'tab-select' switches to the window configuration by its name; +'tab-previous' switches to the previous window configuration; +'tab-next' switches to the next window configuration; +'tab-list' displays a list of named window configurations for switching. + +** 'global-tab-line-mode' enables the tab-line above each window to +switch buffers in it to previous/next buffers. Selecting a previous +window-local tab is the same as running 'C-x <left>' (previous-buffer), +selecting a next tab switches to the tab available by 'C-x <right>' +(next-buffer). Clicking on the plus icon adds a new buffer to the +window-local tab-line of window buffers. Using the mouse wheel on the +tab-line scrolls the window buffers whose names are displayed in tabs. + ** fileloop.el lets one setup multifile operations like search&replace. +++

index 67de79f8a9..2c36f5bfe4 100644

--- a/

+++ b/ diff --git a/etc/TODO b/etc/TODOindex 67de79f8a9..2c36f5bfe4 100644--- a/ etc/TODO +++ b/ etc/TODO @@ -324,20 +324,6 @@ consistency checks that make sure the new code computes the same results as the old code. And once that works well, we can remove the old code and old fields. -** Having tabs above a window to switch buffers in it. - -** "Perspectives" are named persistent window configurations. We have -had the window configuration mechanism in GNU Emacs since the -beginning but we have never developed a good user interface to take -advantage of them. Eclipse's user interface seems to be good. - -Perspectives work well even if you do the equivalent of C-x 4 C-f -because of the distinction between view windows vs file windows. In -Emacs this is more or less the "dedicated window" feature, but we have -never really made it work for this. - -Perspectives also need to interact with the tabs. - ** FFI (foreign function interface) See eg https://lists.gnu.org/r/emacs-devel/2013-10/msg00246.html

new file mode 100644

index 0000000000..1e9f4e5b59

--- /dev/null

+++ b/ diff --git a/etc/images/tabs/README b/etc/images/tabs/READMEnew file mode 100644index 0000000000..1e9f4e5b59--- /dev/null+++ b/ etc/images/tabs/README @@ -0,0 +1,8 @@ +This directory contains icons for the Tabs user interface. + +COPYRIGHT AND LICENSE INFORMATION FOR IMAGE FILES + +Files: close.xpm new.xpm +Author: Juri Linkov <juri@linkov.net> +Copyright (C) 2019 Free Software Foundation, Inc. +License: GNU General Public License version 3 or later (see COPYING)

new file mode 100644

index 0000000000..1c3f4d8fd7

--- /dev/null

+++ b/ diff --git a/etc/images/tabs/close.xpm b/etc/images/tabs/close.xpmnew file mode 100644index 0000000000..1c3f4d8fd7--- /dev/null+++ b/ etc/images/tabs/close.xpm @@ -0,0 +1,16 @@ +/* XPM */ +static char * close_xpm[] = { +"9 9 4 1", +" c None", +". c #BFBFBF", +"+ c #000000", +"@ c #808080", +" ..... ", +" ....... ", +"..+@.@+..", +"..@+@+@..", +"...@+@...", +"..@+@+@..", +"..+@.@+..", +" ....... ", +" ..... "};

new file mode 100644

index 0000000000..e10a8ef238

--- /dev/null

+++ b/ diff --git a/etc/images/tabs/new.xpm b/etc/images/tabs/new.xpmnew file mode 100644index 0000000000..e10a8ef238--- /dev/null+++ b/ etc/images/tabs/new.xpm @@ -0,0 +1,16 @@ +/* XPM */ +static char * new_xpm[] = { +"9 9 4 1", +" c None", +". c #BFBFBF", +"+ c #808080", +"@ c #000000", +".........", +"....+....", +"....@....", +"....@....", +".+@@@@@+.", +"....@....", +"....@....", +"....+....", +"........."};

index 15d33b43c0..e61c1954a1 100644

--- a/

+++ b/ diff --git a/lisp/cus-start.el b/lisp/cus-start.elindex 15d33b43c0..e61c1954a1 100644--- a/ lisp/cus-start.el +++ b/ lisp/cus-start.el @@ -324,6 +324,9 @@ Leaving \"Default\" unchecked is equivalent with specifying a default of ;; FIXME? ;; :initialize custom-initialize-default :set custom-set-minor-mode) + (tab-bar-mode (frames mouse) boolean nil + ;; :initialize custom-initialize-default + :set custom-set-minor-mode) (tool-bar-mode (frames mouse) boolean nil ;; :initialize custom-initialize-default :set custom-set-minor-mode) @@ -726,6 +729,8 @@ since it could result in memory overflow and make Emacs crash." ;; the condition for loadup.el to preload tool-bar.el. ((string-match "tool-bar-" (symbol-name symbol)) (fboundp 'x-create-frame)) + ((string-match "tab-bar-" (symbol-name symbol)) + (fboundp 'x-create-frame)) ((equal "vertical-centering-font-regexp" (symbol-name symbol)) ;; Any function from fontset.c will do.

index e9d4b2ebe4..0c68fc378b 100644

--- a/

+++ b/ diff --git a/lisp/frame.el b/lisp/frame.elindex e9d4b2ebe4..0c68fc378b 100644--- a/ lisp/frame.el +++ b/ lisp/frame.el @@ -363,6 +363,47 @@ there (in decreasing order of priority)." ;; If the initial frame is still around, apply initial-frame-alist ;; and default-frame-alist to it. (when (frame-live-p frame-initial-frame) + ;; When tab-bar has been switched off, correct the frame size + ;; by the lines added in x-create-frame for the tab-bar and + ;; switch `tab-bar-mode' off. + (when (display-graphic-p) + (let* ((init-lines + (assq 'tab-bar-lines initial-frame-alist)) + (other-lines + (or (assq 'tab-bar-lines window-system-frame-alist) + (assq 'tab-bar-lines default-frame-alist))) + (lines (or init-lines other-lines)) + (height (tab-bar-height frame-initial-frame t))) + ;; Adjust frame top if either zero (nil) tab bar lines have + ;; been requested in the most relevant of the frame's alists + ;; or tab bar mode has been explicitly turned off in the + ;; user's init file. + (when (and (> height 0) + (or (and lines + (or (null (cdr lines)) + (eq 0 (cdr lines)))) + (not tab-bar-mode))) + (let* ((initial-top + (cdr (assq 'top frame-initial-geometry-arguments))) + (top (frame-parameter frame-initial-frame 'top))) + (when (and (consp initial-top) (eq '- (car initial-top))) + (let ((adjusted-top + (cond + ((and (consp top) (eq '+ (car top))) + (list '+ (+ (cadr top) height))) + ((and (consp top) (eq '- (car top))) + (list '- (- (cadr top) height))) + (t (+ top height))))) + (modify-frame-parameters + frame-initial-frame `((top . ,adjusted-top)))))) + ;; Reset `tab-bar-mode' when zero tab bar lines have been + ;; requested for the window-system or default frame alists. + (when (and tab-bar-mode + (and other-lines + (or (null (cdr other-lines)) + (eq 0 (cdr other-lines))))) + (tab-bar-mode -1))))) + ;; When tool-bar has been switched off, correct the frame size ;; by the lines added in x-create-frame for the tool-bar and ;; switch `tool-bar-mode' off. @@ -1593,6 +1634,7 @@ and width values are in pixels. '(tool-bar-external . nil) '(tool-bar-position . nil) '(tool-bar-size 0 . 0) + '(tab-bar-size 0 . 0) (cons 'internal-border-width (frame-parameter frame 'internal-border-width)))))))

index 67e8aa7d40..e60922e380 100644

--- a/

+++ b/ diff --git a/lisp/loadup.el b/lisp/loadup.elindex 67e8aa7d40..e60922e380 100644--- a/ lisp/loadup.el +++ b/ lisp/loadup.el @@ -267,6 +267,7 @@ (load "rfn-eshadow") (load "menu-bar") +(load "tab-bar") (load "emacs-lisp/lisp") (load "textmodes/page") (load "register")

index 19122125c5..b7967b858a 100644

--- a/

+++ b/ diff --git a/lisp/menu-bar.el b/lisp/menu-bar.elindex 19122125c5..b7967b858a 100644--- a/ lisp/menu-bar.el +++ b/ lisp/menu-bar.el @@ -687,7 +687,7 @@ The selected font will be the default on both the existing and future frames." ;; side-effect that turning them off via X ;; resources acts like having customized them, but ;; that seems harmless. - menu-bar-mode tool-bar-mode)) + menu-bar-mode tab-bar-mode tool-bar-mode)) ;; FIXME ? It's a little annoying that running this command ;; always loads cua-base, paren, time, and battery, even if they ;; have not been customized in any way. (Due to custom-load-symbol.) @@ -1242,6 +1242,14 @@ mail status in mode line")) (frame-parameter (menu-bar-frame-for-menubar) 'menu-bar-lines))))) + (bindings--define-key menu [showhide-tab-bar] + '(menu-item "Tab Bar" toggle-tab-bar-mode-from-frame + :help "Turn tab bar on/off" + :button + (:toggle . (menu-bar-positive-p + (frame-parameter (menu-bar-frame-for-menubar) + 'tab-bar-lines))))) + (if (and (boundp 'menu-bar-showhide-tool-bar-menu) (keymapp menu-bar-showhide-tool-bar-menu)) (bindings--define-key menu [showhide-tool-bar]

index 123ce2ca15..76fec507e7 100644

--- a/

+++ b/ diff --git a/lisp/mouse.el b/lisp/mouse.elindex 123ce2ca15..76fec507e7 100644--- a/ lisp/mouse.el +++ b/ lisp/mouse.el @@ -2734,6 +2734,7 @@ is copied instead of being cut." ;; versions. (global-set-key [header-line down-mouse-1] 'mouse-drag-header-line) (global-set-key [header-line mouse-1] 'mouse-select-window) +(global-set-key [tab-line mouse-1] 'mouse-select-window) ;; (global-set-key [mode-line drag-mouse-1] 'mouse-select-window) (global-set-key [mode-line down-mouse-1] 'mouse-drag-mode-line) (global-set-key [mode-line mouse-1] 'mouse-select-window)

index 52d4dbb05c..393d787256 100644

--- a/

+++ b/ diff --git a/lisp/startup.el b/lisp/startup.elindex 52d4dbb05c..393d787256 100644--- a/ lisp/startup.el +++ b/ lisp/startup.el @@ -769,6 +769,7 @@ It is the default value of the variable `top-level'." ("--background-color" . "-bg") ("--color" . "-color"))) +;; FIXME: this var unused? (defconst tool-bar-images-pixel-height 24 "Height in pixels of images in the tool-bar.") @@ -1300,6 +1301,7 @@ please check its value") (unless (daemonp) (if (or noninteractive emacs-basic-display) (setq menu-bar-mode nil + tab-bar-mode nil tool-bar-mode nil no-blinking-cursor t)) (frame-initialize)) @@ -1515,6 +1517,7 @@ This can set the values of `menu-bar-mode', `tool-bar-mode', and settings will be marked as \"CHANGED outside of Customize\"." (let ((no-vals '("no" "off" "false" "0")) (settings '(("menuBar" "MenuBar" menu-bar-mode nil) + ("tabBar" "TabBar" tab-bar-mode nil) ("toolBar" "ToolBar" tool-bar-mode nil) ("scrollBar" "ScrollBar" scroll-bar-mode nil) ("cursorBlink" "CursorBlink" no-blinking-cursor t))))

index 45b99a82d2..da619fef14 100644

--- a/

+++ b/ diff --git a/lisp/subr.el b/lisp/subr.elindex 45b99a82d2..da619fef14 100644--- a/ lisp/subr.el +++ b/ lisp/subr.el @@ -2395,8 +2395,12 @@ some sort of escape sequence, the ambiguity is resolved via `read-key-delay'." (progn (use-global-map (let ((map (make-sparse-keymap))) - ;; Don't hide the menu-bar and tool-bar entries. + ;; Don't hide the menu-bar, tab-bar and tool-bar entries. (define-key map [menu-bar] (lookup-key global-map [menu-bar])) + (define-key map [tab-bar] + ;; This hack avoids evaluating the :filter (Bug#9922). + (or (cdr (assq 'tab-bar global-map)) + (lookup-key global-map [tab-bar]))) (define-key map [tool-bar] ;; This hack avoids evaluating the :filter (Bug#9922). (or (cdr (assq 'tool-bar global-map))

new file mode 100644

index 0000000000..42d40a9654

--- /dev/null

+++ b/ diff --git a/lisp/tab-bar.el b/lisp/tab-bar.elnew file mode 100644index 0000000000..42d40a9654--- /dev/null+++ b/ lisp/tab-bar.el @@ -0,0 +1,764 @@ +;;; tab-bar.el --- frame-local tabs with named persistent window configurations -*- lexical-binding: t; -*- + +;; Copyright (C) 2019 Free Software Foundation, Inc. + +;; Author: Juri Linkov <juri@linkov.net> +;; Keywords: frames tabs +;; Maintainer: emacs-devel@gnu.org + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Provides `tab-bar-mode' to control display of the tab bar and +;; bindings for the global tab bar. + +;; The normal global binding for [tab-bar] (below) uses the value of +;; `tab-bar-map' as the actual keymap to define the tab bar. Modes +;; may either bind items under the [tab-bar] prefix key of the local +;; map to add to the global bar or may set `tab-bar-map' +;; buffer-locally to override it. + +;;; Code: + + +(defgroup tab-bar nil + "Frame-local tabs." + :group 'convenience + :version "27.1") + +(defgroup tab-bar-faces nil + "Faces used in the tab bar." + :group 'tab-bar + :group 'faces + :version "27.1") + +(defface tab-bar + '((((type x w32 ns) (class color)) + :height 1.1 + :background "grey85" + :foreground "black") + (((type x) (class mono)) + :background "grey") + (t + :inverse-video t)) + "Tab bar face." + :version "27.1" + :group 'tab-bar-faces) + +(defface tab-bar-tab + '((((class color) (min-colors 88)) + :box (:line-width 1 :style released-button)) + (t + :inverse-video nil)) + "Tab bar face for selected tab." + :version "27.1" + :group 'tab-bar-faces) + +(defface tab-bar-tab-inactive + '((default + :inherit tab-bar-tab) + (((class color) (min-colors 88)) + :background "grey75") + (t + :inverse-video t)) + "Tab bar face for non-selected tab." + :version "27.1" + :group 'tab-bar-faces) + + +(define-minor-mode tab-bar-mode + "Toggle the tab bar in all graphical frames (Tab Bar mode)." + :global t + ;; It's defined in C/cus-start, this stops the d-m-m macro defining it again. + :variable tab-bar-mode + (let ((val (if tab-bar-mode 1 0))) + (dolist (frame (frame-list)) + (set-frame-parameter frame 'tab-bar-lines val)) + ;; If the user has given `default-frame-alist' a `tab-bar-lines' + ;; parameter, replace it. + (if (assq 'tab-bar-lines default-frame-alist) + (setq default-frame-alist + (cons (cons 'tab-bar-lines val) + (assq-delete-all 'tab-bar-lines + default-frame-alist))))) + (when tab-bar-mode + (global-set-key [(control shift iso-lefttab)] 'tab-bar-switch-to-prev-tab) + (global-set-key [(control shift tab)] 'tab-bar-switch-to-prev-tab) + (global-set-key [(control tab)] 'tab-bar-switch-to-next-tab))) + +(defun tab-bar-handle-mouse (event) + "Text-mode emulation of switching tabs on the tab bar. +This command is used when you click the mouse in the tab bar +on a console which has no window system but does have a mouse." + (interactive "e") + (let* ((x-position (car (posn-x-y (event-start event)))) + (keymap (lookup-key (cons 'keymap (nreverse (current-active-maps))) [tab-bar])) + (column 0)) + (when x-position + (unless (catch 'done + (map-keymap + (lambda (_key binding) + (when (eq (car-safe binding) 'menu-item) + (when (> (+ column (length (nth 1 binding))) x-position) + ;; TODO: handle close + (unless (get-text-property (- x-position column) 'close-tab (nth 1 binding)) + (call-interactively (nth 2 binding))) + (throw 'done t)) + (setq column (+ column (length (nth 1 binding)))))) + keymap)) + ;; Clicking anywhere outside existing tabs will add a new tab + (tab-bar-new-tab))))) + +;; Used in the Show/Hide menu, to have the toggle reflect the current frame. +(defun toggle-tab-bar-mode-from-frame (&optional arg) + "Toggle tab bar on or off, based on the status of the current frame. +See `tab-bar-mode' for more information." + (interactive (list (or current-prefix-arg 'toggle))) + (if (eq arg 'toggle) + (tab-bar-mode (if (> (frame-parameter nil 'tab-bar-lines) 0) 0 1)) + (tab-bar-mode arg))) + +(defvar tab-bar-map (make-sparse-keymap) + "Keymap for the tab bar. +Define this locally to override the global tab bar.") + +(global-set-key [tab-bar] + `(menu-item ,(purecopy "tab bar") ignore + :filter tab-bar-make-keymap)) + +(defconst tab-bar-keymap-cache (make-hash-table :weakness t :test 'equal)) + +(defun tab-bar-make-keymap (&optional _ignore) + "Generate an actual keymap from `tab-bar-map'. +Its main job is to show tabs in the tab bar." + (if (= 1 (length tab-bar-map)) + (tab-bar-make-keymap-1) + (let ((key (cons (frame-terminal) tab-bar-map))) + (or (gethash key tab-bar-keymap-cache) + (puthash key tab-bar-map tab-bar-keymap-cache))))) + + +(defcustom tab-bar-new-tab-choice t + "Defines what to show in a new tab. +If t, start a new tab with the current buffer, i.e. the buffer +that was current before calling the command that adds a new tab +(this is the same what `make-frame' does by default). +If the value is a string, switch to a buffer if it exists, or switch +to a buffer visiting the file or directory that the string specifies. +If the value is a function, call it with no arguments and switch to +the buffer that it returns. +If nil, duplicate the contents of the tab that was active +before calling the command that adds a new tab." + :type '(choice (const :tag "Current buffer" t) + (directory :tag "Directory" :value "~/") + (file :tag "File" :value "~/.emacs") + (string :tag "Buffer" "*scratch*") + (function :tag "Function") + (const :tag "Duplicate tab" nil)) + :group 'tab-bar + :version "27.1") + +(defvar tab-bar-new-button + (propertize " + " + 'display `(image :type xpm + :file ,(expand-file-name + "images/tabs/new.xpm" + data-directory) + :margin (2 . 0) + :ascent center)) + "Button for creating a new tab.") + +(defcustom tab-bar-close-button-show t + "Defines where to show the close tab button. +If t, show the close tab button on all tabs. +If `selected', show it only on the selected tab. +If `non-selected', show it only on non-selected tab. +If nil, don't show it at all." + :type '(choice (const :tag "On all tabs" t) + (const :tag "On selected tab" selected) + (const :tag "On non-selected tabs" non-selected) + (const :tag "None" nil)) + :set (lambda (sym val) + (set sym val) + (force-mode-line-update)) + :group 'tab-bar + :version "27.1") + +(defvar tab-bar-close-button + (propertize " x" + 'display `(image :type xpm + :file ,(expand-file-name + "images/tabs/close.xpm" + data-directory) + :margin (2 . 0) + :ascent center) + 'close-tab t + :help "Click to close tab") + "Button for closing the clicked tab.") + +(defvar tab-bar-separator nil) + + +(defvar tab-bar-tab-name-function #'tab-bar-tab-name + "Function to get a tab name. +Function gets no arguments. +By default, use function `tab-bar-tab-name'.") + +(defun tab-bar-tab-name () + "Generate tab name in the context of the selected frame." + (mapconcat #'buffer-name + (delete-dups (mapcar #'window-buffer + (window-list-1 (frame-first-window) + 'nomini))) + ", ")) + +(defvar tab-bar-tabs-function #'tab-bar-tabs + "Function to get a list of tabs to display in the tab bar. +This function should return a list of alists with parameters +that include at least the element (name . TAB-NAME). +For example, '((tab (name . \"Tab 1\")) (current-tab (name . \"Tab 2\"))) +By default, use function `tab-bar-tabs'.") + +(defun tab-bar-tabs () + "Return a list of tabs belonging to the selected frame. +Ensure the frame parameter `tabs' is pre-populated. +Return its existing value or a new value." + (let ((tabs (frame-parameter nil 'tabs))) + (if tabs + ;; Update current tab name + (let ((name (assq 'name (assq 'current-tab tabs)))) + (when name (setcdr name (funcall tab-bar-tab-name-function)))) + ;; Create default tabs + (setq tabs `((current-tab (name . ,(funcall tab-bar-tab-name-function))))) + (set-frame-parameter nil 'tabs tabs)) + tabs)) + +(defun tab-bar-make-keymap-1 () + "Generate an actual keymap from `tab-bar-map', without caching." + (let ((separator (or tab-bar-separator (if window-system " " "|"))) + (i 0)) + (append + '(keymap (mouse-1 . tab-bar-handle-mouse)) + (mapcan + (lambda (tab) + (setq i (1+ i)) + (append + `((,(intern (format "sep-%i" i)) menu-item ,separator ignore)) + (cond + ((eq (car tab) 'current-tab) + `((current-tab + menu-item + ,(propertize (concat (cdr (assq 'name tab)) + (or (and tab-bar-close-button-show + (not (eq tab-bar-close-button-show + 'non-selected)) + tab-bar-close-button) "")) + 'face 'tab-bar-tab) + ignore + :help "Current tab"))) + (t + `((,(intern (format "tab-%i" i)) + menu-item + ,(propertize (concat (cdr (assq 'name tab)) + (or (and tab-bar-close-button-show + (not (eq tab-bar-close-button-show + 'selected)) + tab-bar-close-button) "")) + 'face 'tab-bar-tab-inactive) + ,(or + (cdr (assq 'binding tab)) + (lambda () + (interactive) + (tab-bar-select-tab tab))) + :help "Click to visit tab")))) + `((,(if (eq (car tab) 'current-tab) 'C-current-tab (intern (format "C-tab-%i" i))) + menu-item "" + ,(or + (cdr (assq 'close-binding tab)) + (lambda () + (interactive) + (tab-bar-close-tab tab))))))) + (funcall tab-bar-tabs-function)) + (when tab-bar-new-button + `((sep-add-tab menu-item ,separator ignore) + (add-tab menu-item ,tab-bar-new-button tab-bar-new-tab + :help "New tab")))))) + + +(defun tab-bar-read-tab-name (prompt) + (let* ((tabs (tab-bar-tabs)) + (tab-name + (completing-read prompt + (or (delq nil (mapcar (lambda (tab) + (cdr (assq 'name tab))) + tabs)) + '(""))))) + (catch 'done + (dolist (tab tabs) + (when (equal (cdr (assq 'name tab)) tab-name) + (throw 'done tab)))))) + +(defun tab-bar-tab-default () + (let ((tab `(tab + (name . ,(funcall tab-bar-tab-name-function)) + (time . ,(time-convert nil 'integer)) + (wc . ,(current-window-configuration)) + (ws . ,(window-state-get + (frame-root-window (selected-frame)) 'writable))))) + tab)) + +(defun tab-bar-find-prev-tab (&optional tabs) + (unless tabs + (setq tabs (tab-bar-tabs))) + (unless (eq (car (car tabs)) 'current-tab) + (while (and tabs (not (eq (car (car (cdr tabs))) 'current-tab))) + (setq tabs (cdr tabs))) + tabs)) + + +(defun tab-bar-select-tab (tab) + "Switch to the specified TAB." + (interactive (list (tab-bar-read-tab-name "Select tab by name: "))) + (when (and tab (not (eq (car tab) 'current-tab))) + (let* ((tabs (tab-bar-tabs)) + (new-tab (tab-bar-tab-default)) + (wc (cdr (assq 'wc tab)))) + ;; During the same session, use window-configuration to switch + ;; tabs, because window-configurations are more reliable + ;; (they keep references to live buffers) than window-states. + ;; But after restoring tabs from a previously saved session, + ;; its value of window-configuration is unreadable, + ;; so restore its saved window-state. + (if (window-configuration-p wc) + (set-window-configuration wc) + (window-state-put (cdr (assq 'ws tab)) + (frame-root-window (selected-frame)) 'safe)) + (while tabs + (cond + ((eq (car tabs) tab) + (setcar tabs `(current-tab (name . ,(funcall tab-bar-tab-name-function))))) + ((eq (car (car tabs)) 'current-tab) + (setcar tabs new-tab))) + (setq tabs (cdr tabs))) + (force-mode-line-update)))) + +(defun tab-bar-switch-to-prev-tab (&optional _arg) + "Switch to ARGth previous tab." + (interactive "p") + (let ((prev-tab (tab-bar-find-prev-tab))) + (when prev-tab + (tab-bar-select-tab (car prev-tab))))) + +(defun tab-bar-switch-to-next-tab (&optional _arg) + "Switch to ARGth next tab." + (interactive "p") + (let* ((tabs (tab-bar-tabs)) + (prev-tab (tab-bar-find-prev-tab tabs))) + (if prev-tab + (tab-bar-select-tab (car (cdr (cdr prev-tab)))) + (tab-bar-select-tab (car (cdr tabs)))))) + + +(defcustom tab-bar-new-tab-to 'right + "Defines where to create a new tab. +If `leftmost', create as the first tab. +If `left', create to the left from the current tab. +If `right', create to the right from the current tab. +If `rightmost', create as the last tab." + :type '(choice (const :tag "First tab" leftmost) + (const :tag "To the left" left) + (const :tag "To the right" right) + (const :tag "Last tab" rightmost)) + :group 'tab-bar + :version "27.1") + +(defun tab-bar-new-tab () + "Clone the current tab to the position specified by `tab-bar-new-tab-to'." + (interactive) + (unless tab-bar-mode + (tab-bar-mode 1)) + (let* ((tabs (tab-bar-tabs)) + ;; (i-tab (- (length tabs) (length (memq tab tabs)))) + (new-tab (tab-bar-tab-default))) + (cond + ((eq tab-bar-new-tab-to 'leftmost) + (setq tabs (cons new-tab tabs))) + ((eq tab-bar-new-tab-to 'rightmost) + (setq tabs (append tabs (list new-tab)))) + (t + (let ((prev-tab (tab-bar-find-prev-tab tabs))) + (cond + ((eq tab-bar-new-tab-to 'left) + (if prev-tab + (setcdr prev-tab (cons new-tab (cdr prev-tab))) + (setq tabs (cons new-tab tabs)))) + ((eq tab-bar-new-tab-to 'right) + (if prev-tab + (setq prev-tab (cdr prev-tab)) + (setq prev-tab tabs)) + (setcdr prev-tab (cons new-tab (cdr prev-tab)))))))) + (set-frame-parameter nil 'tabs tabs) + (tab-bar-select-tab new-tab) + (when tab-bar-new-tab-choice + (delete-other-windows) + (let ((buffer + (if (functionp tab-bar-new-tab-choice) + (funcall tab-bar-new-tab-choice) + (if (stringp tab-bar-new-tab-choice) + (or (get-buffer tab-bar-new-tab-choice) + (find-file-noselect tab-bar-new-tab-choice)))))) + (when (buffer-live-p buffer) + (switch-to-buffer buffer)))) + (unless tab-bar-mode + (message "Added new tab with the current window configuration")))) + + +(defcustom tab-bar-close-tab-select 'right + "Defines what tab to select after closing the specified tab. +If `left', select the adjacent left tab. +If `right', select the adjacent right tab." + :type '(choice (const :tag "Select left tab" left) + (const :tag "Select right tab" right)) + :group 'tab-bar + :version "27.1") + +(defun tab-bar-close-current-tab (&optional tab select-tab) + "Close the current TAB. +After closing the current tab switch to the tab +specified by `tab-bar-close-tab-select', or to `select-tab' +if its value is provided." + (interactive) + (let ((tabs (tab-bar-tabs))) + (unless tab + (let ((prev-tab (tab-bar-find-prev-tab tabs))) + (setq tab (if prev-tab + (car (cdr prev-tab)) + (car tabs))))) + (if select-tab + (setq tabs (delq tab tabs)) + (let* ((i-tab (- (length tabs) (length (memq tab tabs)))) + (i-select + (cond + ((eq tab-bar-close-tab-select 'left) + (1- i-tab)) + ((eq tab-bar-close-tab-select 'right) + ;; Do nothing: the next tab will take + ;; the index of the closed tab + i-tab) + (t 0)))) + (setq tabs (delq tab tabs) + i-select (max 0 (min (1- (length tabs)) i-select)) + select-tab (nth i-select tabs)))) + (set-frame-parameter nil 'tabs tabs) + (tab-bar-select-tab select-tab))) + +(defun tab-bar-close-tab (tab) + "Close the specified TAB. +After closing the current tab switch to the tab +specified by `tab-bar-close-tab-select'." + (interactive (list (tab-bar-read-tab-name "Close tab by name: "))) + (when tab + (if (eq (car tab) 'current-tab) + (tab-bar-close-current-tab tab) + ;; Close non-current tab, no need to switch to another tab + (set-frame-parameter nil 'tabs (delq tab (tab-bar-tabs))) + (force-mode-line-update)))) + + +;;; Non-graphical access to frame-local tabs (named window configurations) + +(defun tab-new () + "Create a new named window configuration without having to click a tab." + (interactive) + (tab-bar-new-tab) + (unless tab-bar-mode + (message "Added new tab with the current window configuration"))) + +(defun tab-close () + "Delete the current window configuration without clicking a close button." + (interactive) + (tab-bar-close-current-tab) + (unless tab-bar-mode + (message "Deleted the current tab"))) + +;; Short aliases +;; (defalias 'tab-switch 'tab-bar-switch-to-next-tab) +(defalias 'tab-select 'tab-bar-select-tab) +(defalias 'tab-previous 'tab-bar-switch-to-prev-tab) +(defalias 'tab-next 'tab-bar-switch-to-next-tab) +(defalias 'tab-list 'tab-bar-list) + +(defun tab-bar-list () + "Display a list of named window configurations. +The list is displayed in the buffer `*Tabs*'. + +In this list of window configurations you can delete or select them. +Type ? after invocation to get help on commands available. +Type q to remove the list of window configurations from the display. + +The first column shows `D' for for a window configuration you have +marked for deletion." + (interactive) + (let ((dir default-directory) + (minibuf (minibuffer-selected-window))) + (let ((tab-bar-mode t)) ; don't enable tab-bar-mode if it's disabled + (tab-bar-new-tab)) + ;; Handle the case when it's called in the active minibuffer. + (when minibuf (select-window (minibuffer-selected-window))) + (delete-other-windows) + ;; Create a new window to replace the existing one, to not break the + ;; window parameters (e.g. prev/next buffers) of the window just saved + ;; to the window configuration. So when a saved window is restored, + ;; its parameters left intact. + (split-window) (delete-window) + (let ((switch-to-buffer-preserve-window-point nil)) + (switch-to-buffer (tab-bar-list-noselect))) + (setq default-directory dir)) + (message "Commands: d, x; RET; q to quit; ? for help.")) + +(defun tab-bar-list-noselect () + "Create and return a buffer with a list of window configurations. +The list is displayed in a buffer named `*Tabs*'. + +For more information, see the function `tab-bar-list'." + (let* ((tabs (delq nil (mapcar (lambda (tab) ; remove current tab + (unless (eq (car tab) 'current-tab) + tab)) + (tab-bar-tabs)))) + ;; Sort by recency + (tabs (sort tabs (lambda (a b) (< (cdr (assq 'time b)) + (cdr (assq 'time a))))))) + (with-current-buffer (get-buffer-create + (format " *Tabs*<%s>" (or (frame-parameter nil 'window-id) + (frame-parameter nil 'name)))) + (erase-buffer) + (tab-bar-list-mode) + (setq buffer-read-only nil) + ;; Vertical alignment to the center of the frame + (insert-char ?

(/ (- (frame-height) (length tabs) 1) 2)) + ;; Horizontal alignment to the center of the frame + (setq tab-bar-list-column (- (/ (frame-width) 2) 15)) + (dolist (tab tabs) + (insert (propertize + (format "%s %s

" + (make-string tab-bar-list-column ?\040) + (propertize + (cdr (assq 'name tab)) + 'mouse-face 'highlight + 'help-echo "mouse-2: select this window configuration")) + 'tab tab))) + (goto-char (point-min)) + (goto-char (or (next-single-property-change (point) 'tab) (point-min))) + (when (> (length tabs) 1) + (tab-bar-list-next-line)) + (move-to-column tab-bar-list-column) + (set-buffer-modified-p nil) + (current-buffer)))) + +(defvar tab-bar-list-column 3) +(make-variable-buffer-local 'tab-bar-list-column) + +(defvar tab-bar-list-mode-map + (let ((map (make-keymap))) + (suppress-keymap map t) + (define-key map "q" 'quit-window) + (define-key map "\C-m" 'tab-bar-list-select) + (define-key map "d" 'tab-bar-list-delete) + (define-key map "k" 'tab-bar-list-delete) + (define-key map "\C-d" 'tab-bar-list-delete-backwards) + (define-key map "\C-k" 'tab-bar-list-delete) + (define-key map "x" 'tab-bar-list-execute) + (define-key map " " 'tab-bar-list-next-line) + (define-key map "n" 'tab-bar-list-next-line) + (define-key map "p" 'tab-bar-list-prev-line) + (define-key map "\177" 'tab-bar-list-backup-unmark) + (define-key map "?" 'describe-mode) + (define-key map "u" 'tab-bar-list-unmark) + (define-key map [mouse-2] 'tab-bar-list-mouse-select) + (define-key map [follow-link] 'mouse-face) + map) + "Local keymap for `tab-bar-list-mode' buffers.") + +(define-derived-mode tab-bar-list-mode nil "Window Configurations" + "Major mode for selecting a window configuration. +Each line describes one window configuration in Emacs. +Letters do not insert themselves; instead, they are commands. +\\<tab-bar-list-mode-map> +\\[tab-bar-list-mouse-select] -- select window configuration you click on. +\\[tab-bar-list-select] -- select current line's window configuration. +\\[tab-bar-list-delete] -- mark that window configuration to be deleted, and move down. +\\[tab-bar-list-delete-backwards] -- mark that window configuration to be deleted, and move up. +\\[tab-bar-list-execute] -- delete marked window configurations. +\\[tab-bar-list-unmark] -- remove all kinds of marks from current line. + With prefix argument, also move up one line. +\\[tab-bar-list-backup-unmark] -- back up a line and remove marks." + (setq truncate-lines t) + (setq buffer-read-only t)) + +(defun tab-bar-list-current-tab (error-if-non-existent-p) + "Return window configuration described by this line of the list." + (let* ((where (save-excursion + (beginning-of-line) + (+ 2 (point) tab-bar-list-column))) + (tab (and (not (eobp)) (get-text-property where 'tab)))) + (or tab + (if error-if-non-existent-p + (user-error "No window configuration on this line") + nil)))) + + +(defun tab-bar-list-next-line (&optional arg) + (interactive) + (forward-line arg) + (beginning-of-line) + (move-to-column tab-bar-list-column)) + +(defun tab-bar-list-prev-line (&optional arg) + (interactive) + (forward-line (- arg)) + (beginning-of-line) + (move-to-column tab-bar-list-column)) + +(defun tab-bar-list-unmark (&optional backup) + "Cancel all requested operations on window configuration on this line and move down. +Optional prefix arg means move up." + (interactive "P") + (beginning-of-line) + (move-to-column tab-bar-list-column) + (let* ((buffer-read-only nil)) + (delete-char 1) + (insert " ")) + (forward-line (if backup -1 1)) + (move-to-column tab-bar-list-column)) + +(defun tab-bar-list-backup-unmark () + "Move up and cancel all requested operations on window configuration on line above." + (interactive) + (forward-line -1) + (tab-bar-list-unmark) + (forward-line -1) + (move-to-column tab-bar-list-column)) + +(defun tab-bar-list-delete (&optional arg) + "Mark window configuration on this line to be deleted by \\<tab-bar-list-mode-map>\\[tab-bar-list-execute] command. +Prefix arg is how many window configurations to delete. +Negative arg means delete backwards." + (interactive "p") + (let ((buffer-read-only nil)) + (if (or (null arg) (= arg 0)) + (setq arg 1)) + (while (> arg 0) + (delete-char 1) + (insert ?D) + (forward-line 1) + (setq arg (1- arg))) + (while (< arg 0) + (delete-char 1) + (insert ?D) + (forward-line -1) + (setq arg (1+ arg))) + (move-to-column tab-bar-list-column))) + +(defun tab-bar-list-delete-backwards (&optional arg) + "Mark window configuration on this line to be deleted by \\<tab-bar-list-mode-map>\\[tab-bar-list-execute] command. +Then move up one line. Prefix arg means move that many lines." + (interactive "p") + (tab-bar-list-delete (- (or arg 1)))) + +(defun tab-bar-list-delete-from-list (tab) + "Delete the window configuration from both lists." + (set-frame-parameter nil 'tabs (delq tab (tab-bar-tabs)))) + +(defun tab-bar-list-execute () + "Delete window configurations marked with \\<tab-bar-list-mode-map>\\[tab-bar-list-delete] commands." + (interactive) + (save-excursion + (goto-char (point-min)) + (let ((buffer-read-only nil)) + (while (re-search-forward + (format "^%sD" (make-string tab-bar-list-column ?\040)) + nil t) + (forward-char -1) + (let ((tab (tab-bar-list-current-tab nil))) + (when tab + (tab-bar-list-delete-from-list tab) + (beginning-of-line) + (delete-region (point) (progn (forward-line 1) (point)))))))) + (beginning-of-line) + (move-to-column tab-bar-list-column) + (when tab-bar-mode + (force-mode-line-update))) + +(defun tab-bar-list-select () + "Select this line's window configuration. +This command deletes and replaces all the previously existing windows +in the selected frame." + (interactive) + (let* ((select-tab (tab-bar-list-current-tab t))) + (kill-buffer (current-buffer)) + ;; Delete the current window configuration + (tab-bar-close-current-tab nil select-tab) + ;; (tab-bar-select-tab select-tab) + )) + +(defun tab-bar-list-mouse-select (event) + "Select the window configuration whose line you click on." + (interactive "e") + (set-buffer (window-buffer (posn-window (event-end event)))) + (goto-char (posn-point (event-end event))) + (tab-bar-list-select)) + + +(defvar ctl-x-6-map (make-sparse-keymap) + "Keymap for tab commands.") +(defalias 'ctl-x-6-prefix ctl-x-6-map) +(define-key ctl-x-map "6" 'ctl-x-6-prefix) + +(defun switch-to-buffer-other-tab (buffer-or-name &optional norecord) + "Switch to buffer BUFFER-OR-NAME in another tab. +Like \\[switch-to-buffer-other-frame] (which see), but creates a new tab." + (interactive + (list (read-buffer-to-switch "Switch to buffer in other tab: "))) + (tab-bar-new-tab) + (delete-other-windows) + (switch-to-buffer buffer-or-name norecord)) + +(defun find-file-other-tab (filename &optional wildcards) + "Edit file FILENAME, in another tab. +Like \\[find-file-other-frame] (which see), but creates a new tab." + (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)) + (switch-to-buffer-other-tab (car value)) + (mapc 'switch-to-buffer (cdr value)) + value) + (switch-to-buffer-other-tab value)))) + +(define-key ctl-x-6-map "2" 'tab-bar-new-tab) +(define-key ctl-x-6-map "0" 'tab-bar-close-current-tab) +(define-key ctl-x-6-map "b" 'switch-to-buffer-other-tab) +(define-key ctl-x-6-map "f" 'find-file-other-tab) +(define-key ctl-x-6-map "\C-f" 'find-file-other-tab) + + +(provide 'tab-bar) + +;;; tab-bar.el ends here

new file mode 100644

index 0000000000..62e06a797d

--- /dev/null

+++ b/ diff --git a/lisp/tab-line.el b/lisp/tab-line.elnew file mode 100644index 0000000000..62e06a797d--- /dev/null+++ b/ lisp/tab-line.el @@ -0,0 +1,362 @@ +;;; tab-line.el --- window-local tabs with window buffers -*- lexical-binding: t; -*- + +;; Copyright (C) 2019 Free Software Foundation, Inc. + +;; Author: Juri Linkov <juri@linkov.net> +;; Keywords: windows tabs +;; Maintainer: emacs-devel@gnu.org + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. + +;;; Commentary: + +;; To enable this mode, run `M-x global-tab-line-mode'. + +;;; Code: + +(require 'seq) ; tab-line.el is not pre-loaded so it's safe to use it here + + +(defgroup tab-line nil + "Window-local tabs." + :group 'convenience + :version "27.1") + +(defgroup tab-line-faces nil + "Faces used in the tab line." + :group 'tab-line + :group 'faces + :version "27.1") + +(defface tab-line + '((((type x w32 ns) (class color)) + :background "grey85" + :foreground "black") + (((type x) (class mono)) + :background "grey") + (t + :inverse-video t)) + "Tab line face." + :version "27.1" + :group 'tab-line-faces) + +(defface tab-line-tab + '((((class color) (min-colors 88)) + :box (:line-width 1 :style released-button) + :background "grey85") + (t + :inverse-video nil)) + "Tab line face for selected tab." + :version "27.1" + :group 'tab-line-faces) + +(defface tab-line-tab-inactive + '((default + :inherit tab-line-tab) + (((class color) (min-colors 88)) + :background "grey75") + (t + :inverse-video t)) + "Tab line face for non-selected tab." + :version "27.1" + :group 'tab-line-faces) + +(defface tab-line-highlight + '((default :inherit tab-line-tab)) + "Tab line face for highlighting." + :version "27.1" + :group 'tab-line-faces) + +(defface tab-line-close-highlight + '((t :foreground "red")) + "Tab line face for highlighting of the close button." + :version "27.1" + :group 'tab-line-faces) + + +(defvar tab-line-tab-map + (let ((map (make-sparse-keymap))) + (define-key map [tab-line mouse-1] 'tab-line-select-tab) + (define-key map [tab-line mouse-2] 'tab-line-close-tab) + (define-key map [tab-line mouse-4] 'tab-line-switch-to-prev-tab) + (define-key map [tab-line mouse-5] 'tab-line-switch-to-next-tab) + (define-key map "\C-m" 'tab-line-select-tab) + map) + "Local keymap for `tab-line-mode' window tabs.") + +(defvar tab-line-add-map + (let ((map (make-sparse-keymap))) + (define-key map [tab-line mouse-1] 'tab-line-new-tab) + (define-key map [tab-line mouse-2] 'tab-line-new-tab) + (define-key map "\C-m" 'tab-line-new-tab) + map) + "Local keymap to add `tab-line-mode' window tabs.") + +(defvar tab-line-tab-close-map + (let ((map (make-sparse-keymap))) + (define-key map [tab-line mouse-1] 'tab-line-close-tab) + (define-key map [tab-line mouse-2] 'tab-line-close-tab) + map) + "Local keymap to close `tab-line-mode' window tabs.") + + +(defcustom tab-line-new-tab-choice t + "Defines what to show in a new tab. +If t, display a selection menu with all available buffers. +If the value is a function, call it with no arguments. +If nil, don't show the new tab button." + :type '(choice (const :tag "Buffer menu" t) + (function :tag "Function") + (const :tag "No button" nil)) + :group 'tab-line + :version "27.1") + +(defvar tab-line-new-button + (propertize " + " + 'display `(image :type xpm + :file ,(expand-file-name + "images/tabs/new.xpm" + data-directory) + :margin (2 . 0) + :ascent center) + 'keymap tab-line-add-map + 'mouse-face 'tab-line-highlight + 'help-echo "Click to add tab") + "Button for creating a new tab.") + +(defcustom tab-line-close-button-show t + "Defines where to show the close tab button. +If t, show the close tab button on all tabs. +If `selected', show it only on the selected tab. +If `non-selected', show it only on non-selected tab. +If nil, don't show it at all." + :type '(choice (const :tag "On all tabs" t) + (const :tag "On selected tab" selected) + (const :tag "On non-selected tabs" non-selected) + (const :tag "None" nil)) + :set (lambda (sym val) + (set sym val) + (force-mode-line-update)) + :group 'tab-line + :version "27.1") + +(defvar tab-line-close-button + (propertize " x" + 'display `(image :type xpm + :file ,(expand-file-name + "images/tabs/close.xpm" + data-directory) + :margin (2 . 0) + :ascent center) + 'keymap tab-line-tab-close-map + 'mouse-face 'tab-line-close-highlight + 'help-echo "Click to close tab") + "Button for closing the clicked tab.") + +(defvar tab-line-separator nil) + +(defvar tab-line-tab-name-ellipsis + (if (char-displayable-p ?…) "…" "...")) + + +(defvar tab-line-tab-name-function #'tab-line-tab-name + "Function to get a tab name. +Function gets two arguments: tab to get name for and a list of tabs +to display. By default, use function `tab-line-tab-name'.") + +(defun tab-line-tab-name (buffer &optional buffers) + "Generate tab name from BUFFER. +Reduce tab width proportionally to space taken by other tabs. +This function can be overridden by changing the default value of the +variable `tab-line-tab-name-function'." + (let ((tab-name (buffer-name buffer)) + (limit (when buffers + (max 1 (- (/ (window-width) (length buffers)) 3))))) + (if (or (not limit) (< (length tab-name) limit)) + tab-name + (propertize (truncate-string-to-width tab-name limit nil nil + tab-line-tab-name-ellipsis) + 'help-echo tab-name)))) + +(defvar tab-line-tabs-limit 15 + "Maximum number of buffer tabs displayed in the tab line.") + +(defvar tab-line-tabs-function #'tab-line-tabs + "Function to get a list of tabs to display in the tab line. +This function should return either a list of buffers whose names will +be displayed, or just a list of strings to display in the tab line. +By default, use function `tab-line-tabs'.") + +(defun tab-line-tabs () + "Return a list of tabs that should be displayed in the tab line. +By default returns a list of window buffers, i.e. buffers previously +shown in the same window where the tab line is displayed. +This list can be overridden by changing the default value of the +variable `tab-line-tabs-function'." + (let* ((window (selected-window)) + (buffer (window-buffer window)) + (next-buffers (seq-remove (lambda (b) (eq b buffer)) + (window-next-buffers window))) + (next-buffers (seq-filter #'buffer-live-p next-buffers)) + (prev-buffers (seq-remove (lambda (b) (eq b buffer)) + (mapcar #'car (window-prev-buffers window)))) + (prev-buffers (seq-filter #'buffer-live-p prev-buffers)) + ;; Remove next-buffers from prev-buffers + (prev-buffers (seq-difference prev-buffers next-buffers)) + (half-limit (/ tab-line-tabs-limit 2)) + (prev-buffers-limit + (if (> (length prev-buffers) half-limit) + (if (> (length next-buffers) half-limit) + half-limit + (+ half-limit (- half-limit (length next-buffers)))) + (length prev-buffers))) + (next-buffers-limit + (- tab-line-tabs-limit prev-buffers-limit)) + (buffer-tabs + (append (reverse (seq-take prev-buffers prev-buffers-limit)) + (list buffer) + (seq-take next-buffers next-buffers-limit)))) + buffer-tabs)) + +(defun tab-line-format () + "Template for displaying tab line for selected window." + (let* ((window (selected-window)) + (selected-buffer (window-buffer window)) + (tabs (funcall tab-line-tabs-function)) + (separator (or tab-line-separator (if window-system " " "|")))) + (append + (mapcar + (lambda (tab) + (concat + separator + (apply 'propertize (concat (propertize + (funcall tab-line-tab-name-function tab tabs) + 'keymap tab-line-tab-map) + (or (and tab-line-close-button-show + (not (eq tab-line-close-button-show + (if (eq tab selected-buffer) + 'non-selected + 'selected))) + tab-line-close-button) "")) + `( + tab ,tab + face ,(if (eq tab selected-buffer) + 'tab-line-tab + 'tab-line-tab-inactive) + mouse-face tab-line-highlight)))) + tabs) + (list (concat separator (when tab-line-new-tab-choice + tab-line-new-button)))))) + + +(defun tab-line-new-tab (&optional e) + "Add a new tab to the tab line. +Usually is invoked by clicking on the plus-shaped button. +But any switching to other buffer also adds a new tab +corresponding to the switched buffer." + (interactive "e") + (if (functionp tab-line-new-tab-choice) + (funcall tab-line-new-tab-choice) + (if window-system ; (display-popup-menus-p) + (mouse-buffer-menu e) ; like (buffer-menu-open) + ;; tty menu doesn't support mouse clicks, so use tmm + (tmm-prompt (mouse-buffer-menu-keymap))))) + +(defun tab-line-select-tab (&optional e) + "Switch to the selected tab. +This command maintains the original order of prev/next buffers. +So for example, switching to a previous tab is equivalent to +using the `previous-buffer' command." + (interactive "e") + (let* ((posnp (event-start e)) + (window (posn-window posnp)) + (buffer (get-pos-property 1 'tab (car (posn-string posnp)))) + (window-buffer (window-buffer window)) + (next-buffers (seq-remove (lambda (b) (eq b window-buffer)) + (window-next-buffers window))) + (prev-buffers (seq-remove (lambda (b) (eq b window-buffer)) + (mapcar #'car (window-prev-buffers window)))) + ;; Remove next-buffers from prev-buffers + (prev-buffers (seq-difference prev-buffers next-buffers))) + (cond + ((memq buffer next-buffers) + (dotimes (_ (1+ (seq-position next-buffers buffer))) + (switch-to-next-buffer window))) + ((memq buffer prev-buffers) + (dotimes (_ (1+ (seq-position prev-buffers buffer))) + (switch-to-prev-buffer window))) + (t + (with-selected-window window + (switch-to-buffer buffer)))))) + +(defun tab-line-switch-to-prev-tab (&optional e) + "Switch to the previous tab. +Its effect is the same as using the `previous-buffer' command +(\\[previous-buffer])." + (interactive "e") + (switch-to-prev-buffer (posn-window (event-start e)))) + +(defun tab-line-switch-to-next-tab (&optional e) + "Switch to the next tab. +Its effect is the same as using the `next-buffer' command +(\\[next-buffer])." + (interactive "e") + (switch-to-next-buffer (posn-window (event-start e)))) + +(defcustom tab-line-close-tab-action 'bury-buffer + "Defines what to do on closing the tab. +If `bury-buffer', put the tab's buffer at the end of the list of all +buffers that effectively hides the buffer's tab from the tab line. +If `kill-buffer', kills the tab's buffer." + :type '(choice (const :tag "Bury buffer" bury-buffer) + (const :tag "Kill buffer" kill-buffer)) + :group 'tab-line + :version "27.1") + +(defun tab-line-close-tab (&optional e) + "Close the selected tab. +Usually is invoked by clicking on the close button on the right side +of the tab. This command buries the buffer, so it goes out of sight +from the tab line." + (interactive "e") + (let* ((posnp (event-start e)) + (window (posn-window posnp)) + (buffer (get-pos-property 1 'tab (car (posn-string posnp))))) + (with-selected-window window + (cond + ((eq tab-line-close-tab-action 'kill-buffer) + (kill-buffer buffer)) + ((eq tab-line-close-tab-action 'bury-buffer) + (if (eq buffer (current-buffer)) + (bury-buffer) + (set-window-prev-buffers nil (assq-delete-all buffer (window-prev-buffers))) + (set-window-next-buffers nil (delq buffer (window-next-buffers)))))) + (force-mode-line-update)))) + + +;;;###autoload +(define-minor-mode global-tab-line-mode + "Display window-local tab line." + :group 'tab-line + :type 'boolean + :global t + :init-value nil + (setq-default tab-line-format (when global-tab-line-mode + '(:eval (tab-line-format))))) + + +(provide 'tab-line) +;;; tab-line.el ends here

index 620eacdd29..d93ec0add6 100644

--- a/

+++ b/ diff --git a/lisp/window.el b/lisp/window.elindex 620eacdd29..d93ec0add6 100644--- a/ lisp/window.el +++ b/ lisp/window.el @@ -1419,7 +1419,10 @@ dumping to it." (format "frame text pixel: %s x %s cols/lines: %s x %s

" (frame-text-width frame) (frame-text-height frame) (frame-text-cols frame) (frame-text-lines frame)) - (format "tool: %s scroll: %s/%s fringe: %s border: %s right: %s bottom: %s



" + (format "tab: %s tool: %s scroll: %s/%s fringe: %s border: %s right: %s bottom: %s



" + (if (fboundp 'tab-bar-height) + (tab-bar-height frame t) + "0") (if (fboundp 'tool-bar-height) (tool-bar-height frame t) "0")

index 9e8a32a28f..308f602b6d 100644

--- a/

+++ b/ diff --git a/lisp/xt-mouse.el b/lisp/xt-mouse.elindex 9e8a32a28f..308f602b6d 100644--- a/ lisp/xt-mouse.el +++ b/ lisp/xt-mouse.el @@ -253,7 +253,13 @@ which is the \"1006\" extension implemented in Xterm >= 277." (top (nth 1 ltrb)) (posn (if w (posn-at-x-y (- x left) (- y top) w t) - (append (list nil 'menu-bar) + (append (list nil (if (and tab-bar-mode + (or (not menu-bar-mode) + ;; The tab-bar is on the + ;; second row below menu-bar + (eq y 1))) + 'tab-bar + 'menu-bar)) (nthcdr 2 (posn-at-x-y x y))))) (event (list type posn))) (setcar (nthcdr 3 posn) timestamp)

index 77e8b6bb77..8cb28d8aa7 100644

--- a/

+++ b/ diff --git a/src/buffer.c b/src/buffer.cindex 77e8b6bb77..8cb28d8aa7 100644--- a/ src/buffer.c +++ b/ src/buffer.c @@ -249,6 +249,11 @@ bset_header_line_format (struct buffer *b, Lisp_Object val) b->header_line_format_ = val; } static void +bset_tab_line_format (struct buffer *b, Lisp_Object val) +{ + b->tab_line_format_ = val; +} +static void bset_indicate_buffer_boundaries (struct buffer *b, Lisp_Object val) { b->indicate_buffer_boundaries_ = val; @@ -1329,7 +1334,7 @@ No argument or nil as argument means use current buffer as BUFFER. */) DEFUN ("force-mode-line-update", Fforce_mode_line_update, Sforce_mode_line_update, 0, 1, 0, doc: /* Force redisplay of the current buffer's mode line and header line. -With optional non-nil ALL, force redisplay of all mode lines and +With optional non-nil ALL, force redisplay of all mode lines, tab lines and header lines. This function also forces recomputation of the menu bar menus and the frame title. */) (Lisp_Object all) @@ -5194,6 +5199,7 @@ init_buffer_once (void) XSETFASTINT (BVAR (&buffer_local_flags, scroll_up_aggressively), idx); ++idx; XSETFASTINT (BVAR (&buffer_local_flags, scroll_down_aggressively), idx); ++idx; XSETFASTINT (BVAR (&buffer_local_flags, header_line_format), idx); ++idx; + XSETFASTINT (BVAR (&buffer_local_flags, tab_line_format), idx); ++idx; XSETFASTINT (BVAR (&buffer_local_flags, cursor_type), idx); ++idx; XSETFASTINT (BVAR (&buffer_local_flags, extra_line_spacing), idx); ++idx; XSETFASTINT (BVAR (&buffer_local_flags, cursor_in_non_selected_windows), idx); ++idx; @@ -5239,6 +5245,7 @@ init_buffer_once (void) /* real setup is done in bindings.el */ bset_mode_line_format (&buffer_defaults, build_pure_c_string ("%-")); bset_header_line_format (&buffer_defaults, Qnil); + bset_tab_line_format (&buffer_defaults, Qnil); bset_abbrev_mode (&buffer_defaults, Qnil); bset_overwrite_mode (&buffer_defaults, Qnil); bset_case_fold_search (&buffer_defaults, Qt); @@ -5510,6 +5517,13 @@ syms_of_buffer (void) Fput (Qprotected_field, Qerror_message, build_pure_c_string ("Attempt to modify a protected field")); + DEFVAR_PER_BUFFER ("tab-line-format", + &BVAR (current_buffer, tab_line_format), + Qnil, + doc: /* Analogous to `mode-line-format', but controls the tab line. +The tab line appears, optionally, at the top of a window; +the mode line appears at the bottom. */); + DEFVAR_PER_BUFFER ("header-line-format", &BVAR (current_buffer, header_line_format), Qnil,

index 280d4e9098..37a50d276f 100644

--- a/

+++ b/ diff --git a/src/buffer.h b/src/buffer.hindex 280d4e9098..37a50d276f 100644--- a/ src/buffer.h +++ b/ src/buffer.h @@ -348,6 +348,10 @@ struct buffer of windows. Nil means don't display that line. */ Lisp_Object header_line_format_; + /* Analogous to mode_line_format for the line displayed at the top + of windows. Nil means don't display that line. */ + Lisp_Object tab_line_format_; + /* Keys that are bound local to this buffer. */ Lisp_Object keymap_;

index 05f199ff35..817f8c77d9 100644

--- a/

+++ b/ diff --git a/src/dispextern.h b/src/dispextern.hindex 05f199ff35..817f8c77d9 100644--- a/ src/dispextern.h +++ b/ src/dispextern.h @@ -166,6 +166,7 @@ enum window_part ON_MODE_LINE, ON_VERTICAL_BORDER, ON_HEADER_LINE, + ON_TAB_LINE, ON_LEFT_FRINGE, ON_RIGHT_FRINGE, ON_LEFT_MARGIN, @@ -762,6 +763,9 @@ struct glyph_matrix which do their own scrolling. */ bool_bf no_scrolling_p : 1; + /* True means window displayed in this matrix has a tab line. */ + bool_bf tab_line_p : 1; + /* True means window displayed in this matrix has a header line. */ bool_bf header_line_p : 1; @@ -1001,9 +1005,12 @@ struct glyph_row implies that the row doesn't have marginal areas. */ bool_bf full_width_p : 1; - /* True means row is a mode or header-line. */ + /* True means row is a mode or header/tab-line. */ bool_bf mode_line_p : 1; + /* True means row is a tab-line. */ + bool_bf tab_line_p : 1; + /* True in a current row means this row is overlapped by another row. */ bool_bf overlapped_p : 1; @@ -1084,16 +1091,25 @@ struct glyph_row *matrix_row (struct glyph_matrix *, int); #define MATRIX_MODE_LINE_ROW(MATRIX) \ ((MATRIX)->rows + (MATRIX)->nrows - 1) -/* Return a pointer to the row reserved for the header line in MATRIX. +/* Return a pointer to the row reserved for the tab line in MATRIX. This is always the first row in MATRIX because that's the only way that works in frame-based redisplay. */ -#define MATRIX_HEADER_LINE_ROW(MATRIX) (MATRIX)->rows +#define MATRIX_TAB_LINE_ROW(MATRIX) (MATRIX)->rows + +/* Return a pointer to the row reserved for the header line in MATRIX. + This is always the second row in MATRIX because that's the only + way that works in frame-based redisplay. */ + +#define MATRIX_HEADER_LINE_ROW(MATRIX) \ + ((MATRIX)->tab_line_p ? ((MATRIX)->rows + 1) : (MATRIX)->rows) /* Return a pointer to first row in MATRIX used for text display. */ #define MATRIX_FIRST_TEXT_ROW(MATRIX) \ - ((MATRIX)->rows->mode_line_p ? (MATRIX)->rows + 1 : (MATRIX)->rows) + ((MATRIX)->rows->mode_line_p ? \ + (((MATRIX)->rows + 1)->mode_line_p ? \ + (MATRIX)->rows + 2 : (MATRIX)->rows + 1) : (MATRIX)->rows) /* Return a pointer to the first glyph in the text area of a row. MATRIX is the glyph matrix accessed, and ROW is the row index in @@ -1162,7 +1178,7 @@ struct glyph_row *matrix_row (struct glyph_matrix *, int); ((ROW)->height != (ROW)->visible_height) #define MR_PARTIALLY_VISIBLE_AT_TOP(W, ROW) \ - ((ROW)->y < WINDOW_HEADER_LINE_HEIGHT ((W))) + ((ROW)->y < (WINDOW_TAB_LINE_HEIGHT ((W)) + WINDOW_HEADER_LINE_HEIGHT ((W)))) #define MR_PARTIALLY_VISIBLE_AT_BOTTOM(W, ROW) \ (((ROW)->y + (ROW)->height - (ROW)->extra_line_spacing) \ @@ -1433,6 +1449,15 @@ struct glyph_string ? MATRIX_HEADER_LINE_ROW (MATRIX)->height \ : 0) +/* Return the height of the tab line in glyph matrix MATRIX, or zero + if not known. This macro is called under circumstances where + MATRIX might not have been allocated yet. */ + +#define MATRIX_TAB_LINE_HEIGHT(MATRIX) \ + ((MATRIX) && (MATRIX)->rows \ + ? MATRIX_TAB_LINE_ROW (MATRIX)->height \ + : 0) + /* Return the desired face id for the mode line of a window, depending on whether the window is selected or not, or if the window is the scrolling window for the currently active minibuffer window. @@ -1485,6 +1510,19 @@ struct glyph_string : estimate_mode_line_height \ (XFRAME (W->frame), HEADER_LINE_FACE_ID)))) +/* Return the current height of the tab line of window W. If not known + from W->tab_line_height, look at W's current glyph matrix, or return + an estimation based on the height of the font of the face `tab-line'. */ + +#define CURRENT_TAB_LINE_HEIGHT(W) \ + (W->tab_line_height >= 0 \ + ? W->tab_line_height \ + : (W->tab_line_height \ + = (MATRIX_TAB_LINE_HEIGHT (W->current_matrix) \ + ? MATRIX_TAB_LINE_HEIGHT (W->current_matrix) \ + : estimate_mode_line_height \ + (XFRAME (W->frame), TAB_LINE_FACE_ID)))) + /* Return the height of the desired mode line of window W. */ #define DESIRED_MODE_LINE_HEIGHT(W) \ @@ -1495,6 +1533,11 @@ struct glyph_string #define DESIRED_HEADER_LINE_HEIGHT(W) \ MATRIX_HEADER_LINE_HEIGHT ((W)->desired_matrix) +/* Return the height of the desired tab line of window W. */ + +#define DESIRED_TAB_LINE_HEIGHT(W) \ + MATRIX_TAB_LINE_HEIGHT ((W)->desired_matrix) + /* Return proper value to be used as baseline offset of font that has ASCENT and DESCENT to draw characters by the font at the vertical center of the line of frame F. @@ -1780,6 +1823,8 @@ enum face_id WINDOW_DIVIDER_FIRST_PIXEL_FACE_ID, WINDOW_DIVIDER_LAST_PIXEL_FACE_ID, INTERNAL_BORDER_FACE_ID, + TAB_BAR_FACE_ID, + TAB_LINE_FACE_ID, BASIC_FACE_ID_SENTINEL }; @@ -2283,6 +2328,9 @@ struct it /* True means multibyte characters are enabled. */ bool_bf multibyte_p : 1; + /* True means window has a tab line at its top. */ + bool_bf tab_line_p : 1; + /* True means window has a mode line at its top. */ bool_bf header_line_p : 1; @@ -3130,6 +3178,50 @@ struct image_cache /*********************************************************************** + Tab-bars + ***********************************************************************/ + +/* Enumeration defining where to find tab-bar item information in + tab-bar items vectors stored with frames. Each tab-bar item + occupies TAB_BAR_ITEM_NSLOTS elements in such a vector. */ + +enum tab_bar_item_idx +{ + /* The key of the tab-bar item. Used to remove items when a binding + for `undefined' is found. */ + TAB_BAR_ITEM_KEY, + + /* Non-nil if item is enabled. */ + TAB_BAR_ITEM_ENABLED_P, + + /* Non-nil if item is selected (pressed). */ + TAB_BAR_ITEM_SELECTED_P, + + /* Caption. */ + TAB_BAR_ITEM_CAPTION, + + /* The binding. */ + TAB_BAR_ITEM_BINDING, + + /* Help string. */ + TAB_BAR_ITEM_HELP, + + /* Sentinel = number of slots in tab_bar_items occupied by one + tab-bar item. */ + TAB_BAR_ITEM_NSLOTS +}; + +/* Default values of the above variables. */ + +#define DEFAULT_TAB_BAR_BUTTON_MARGIN 4 +#define DEFAULT_TAB_BAR_BUTTON_RELIEF 1 + +/* The height in pixels of the default tab-bar images. */ + +#define DEFAULT_TAB_BAR_IMAGE_HEIGHT 18 + + +/*********************************************************************** Tool-bars ***********************************************************************/ @@ -3285,6 +3377,7 @@ extern bool help_echo_showing_p; extern Lisp_Object help_echo_string, help_echo_window; extern Lisp_Object help_echo_object, previous_help_echo_string; extern ptrdiff_t help_echo_pos; +extern int last_tab_bar_item; extern int last_tool_bar_item; extern void reseat_at_previous_visible_line_start (struct it *); extern Lisp_Object lookup_glyphless_char_display (int, struct it *); @@ -3332,6 +3425,8 @@ extern void get_glyph_string_clip_rect (struct glyph_string *, NativeRectangle *nr); extern Lisp_Object find_hot_spot (Lisp_Object, int, int); +extern void handle_tab_bar_click (struct frame *, + int, int, bool, int); extern void handle_tool_bar_click (struct frame *, int, int, bool, int);

index 799ef2beae..4cf131522e 100644

--- a/

+++ b/ diff --git a/src/dispnew.c b/src/dispnew.cindex 799ef2beae..4cf131522e 100644--- a/ src/dispnew.c +++ b/ src/dispnew.c @@ -80,7 +80,7 @@ static void adjust_decode_mode_spec_buffer (struct frame *); static void fill_up_glyph_row_with_spaces (struct glyph_row *); static void clear_window_matrices (struct window *, bool); static void fill_up_glyph_row_area_with_spaces (struct glyph_row *, int); -static int scrolling_window (struct window *, bool); +static int scrolling_window (struct window *, int); static bool update_window_line (struct window *, int, bool *); static void mirror_make_current (struct window *, int); #ifdef GLYPH_DEBUG @@ -366,6 +366,8 @@ adjust_glyph_matrix (struct window *w, struct glyph_matrix *matrix, int x, int y int i; int new_rows; bool marginal_areas_changed_p = 0; + bool tab_line_changed_p = 0; + bool tab_line_p = 0; bool header_line_changed_p = 0; bool header_line_p = 0; int left = -1, right = -1; @@ -377,9 +379,13 @@ adjust_glyph_matrix (struct window *w, struct glyph_matrix *matrix, int x, int y { window_box (w, ANY_AREA, 0, 0, &window_width, &window_height); + tab_line_p = window_wants_tab_line (w); + tab_line_changed_p = tab_line_p != matrix->tab_line_p; + header_line_p = window_wants_header_line (w); header_line_changed_p = header_line_p != matrix->header_line_p; } + matrix->tab_line_p = tab_line_p; matrix->header_line_p = header_line_p; /* If POOL is null, MATRIX is a window matrix for window-based redisplay. @@ -397,6 +403,7 @@ adjust_glyph_matrix (struct window *w, struct glyph_matrix *matrix, int x, int y if (!marginal_areas_changed_p && !XFRAME (w->frame)->fonts_changed + && !tab_line_changed_p && !header_line_changed_p && matrix->window_pixel_left == WINDOW_LEFT_PIXEL_EDGE (w) && matrix->window_pixel_top == WINDOW_TOP_PIXEL_EDGE (w) @@ -448,7 +455,11 @@ adjust_glyph_matrix (struct window *w, struct glyph_matrix *matrix, int x, int y if (w == NULL || (row == matrix->rows + dim.height - 1 && window_wants_mode_line (w)) - || (row == matrix->rows && matrix->header_line_p)) + || (row == matrix->rows && matrix->tab_line_p) + || (row == matrix->rows + && !matrix->tab_line_p && matrix->header_line_p) + || (row == (matrix->rows + 1) + && matrix->tab_line_p && matrix->header_line_p)) { row->glyphs[TEXT_AREA] = row->glyphs[LEFT_MARGIN_AREA]; @@ -478,6 +489,7 @@ adjust_glyph_matrix (struct window *w, struct glyph_matrix *matrix, int x, int y Allocate glyph memory from the heap. */ if (dim.width > matrix->matrix_w || new_rows + || tab_line_changed_p || header_line_changed_p || marginal_areas_changed_p) { @@ -493,7 +505,11 @@ adjust_glyph_matrix (struct window *w, struct glyph_matrix *matrix, int x, int y /* The mode line, if displayed, never has marginal areas. */ if ((row == matrix->rows + dim.height - 1 && !(w && window_wants_mode_line (w))) - || (row == matrix->rows && matrix->header_line_p)) + || (row == matrix->rows && matrix->tab_line_p) + || (row == matrix->rows + && !matrix->tab_line_p && matrix->header_line_p) + || (row == (matrix->rows + 1) + && matrix->tab_line_p && matrix->header_line_p)) { row->glyphs[TEXT_AREA] = row->glyphs[LEFT_MARGIN_AREA]; @@ -539,6 +555,7 @@ adjust_glyph_matrix (struct window *w, struct glyph_matrix *matrix, int x, int y upper window). Invalidate all rows that are no longer part of the window. */ if (!marginal_areas_changed_p + && !tab_line_changed_p && !header_line_changed_p && new_rows == 0 && dim.width == matrix->matrix_w @@ -728,7 +745,7 @@ shift_glyph_matrix (struct window *w, struct glyph_matrix *matrix, int start, in eassert (start >= 0 && start < matrix->nrows); eassert (end >= 0 && end <= matrix->nrows); - min_y = WINDOW_HEADER_LINE_HEIGHT (w); + min_y = WINDOW_TAB_LINE_HEIGHT (w) + WINDOW_HEADER_LINE_HEIGHT (w); max_y = WINDOW_BOX_HEIGHT_NO_MODE_LINE (w); for (; start < end; ++start) @@ -767,6 +784,12 @@ clear_current_matrices (register struct frame *f) clear_glyph_matrix (XWINDOW (f->menu_bar_window)->current_matrix); #endif +#if defined (HAVE_WINDOW_SYSTEM) + /* Clear the matrix of the tab-bar window, if any. */ + if (WINDOWP (f->tab_bar_window)) + clear_glyph_matrix (XWINDOW (f->tab_bar_window)->current_matrix); +#endif + #if defined (HAVE_WINDOW_SYSTEM) && ! defined (HAVE_EXT_TOOL_BAR) /* Clear the matrix of the tool-bar window, if any. */ if (WINDOWP (f->tool_bar_window)) @@ -792,6 +815,11 @@ clear_desired_matrices (register struct frame *f) clear_glyph_matrix (XWINDOW (f->menu_bar_window)->desired_matrix); #endif +#if defined (HAVE_WINDOW_SYSTEM) + if (WINDOWP (f->tab_bar_window)) + clear_glyph_matrix (XWINDOW (f->tab_bar_window)->desired_matrix); +#endif + #if defined (HAVE_WINDOW_SYSTEM) && ! defined (HAVE_EXT_TOOL_BAR) if (WINDOWP (f->tool_bar_window)) clear_glyph_matrix (XWINDOW (f->tool_bar_window)->desired_matrix); @@ -857,7 +885,7 @@ blank_row (struct window *w, struct glyph_row *row, int y) { int min_y, max_y; - min_y = WINDOW_HEADER_LINE_HEIGHT (w); + min_y = WINDOW_TAB_LINE_HEIGHT (w) + WINDOW_HEADER_LINE_HEIGHT (w); max_y = WINDOW_BOX_HEIGHT_NO_MODE_LINE (w); clear_glyph_row (row); @@ -1062,7 +1090,7 @@ find_glyph_row_slice (struct glyph_matrix *window_matrix, call to this function really clears it. In addition, this function makes sure the marginal areas of ROW are in sync with the window's display margins. MODE_LINE_P non-zero means we are preparing a - glyph row for header line or mode line. */ + glyph row for tab/header line or mode line. */ void prepare_desired_row (struct window *w, struct glyph_row *row, bool mode_line_p) @@ -1077,11 +1105,11 @@ prepare_desired_row (struct window *w, struct glyph_row *row, bool mode_line_p) } if (mode_line_p) { - /* Mode and header lines, if displayed, never have marginal + /* Mode and header/tab lines, if displayed, never have marginal areas. If we are called with MODE_LINE_P non-zero, we are - displaying the mode/header line in this window, and so the + displaying the mode/header/tab line in this window, and so the marginal areas of this glyph row should be eliminated. This - is needed when the mode/header line is switched on in a + is needed when the mode/header/tab line is switched on in a window that has display margins. */ if (w->left_margin_cols > 0) row->glyphs[TEXT_AREA] = row->glyphs[LEFT_MARGIN_AREA]; @@ -1099,7 +1127,7 @@ prepare_desired_row (struct window *w, struct glyph_row *row, bool mode_line_p) /* Make sure the marginal areas of this row are in sync with what the window wants, when the row actually displays text - and not header/mode line. */ + and not tab/header/mode line. */ if (w->left_margin_cols > 0 && (left != row->glyphs[TEXT_AREA] - row->glyphs[LEFT_MARGIN_AREA])) row->glyphs[TEXT_AREA] = row->glyphs[LEFT_MARGIN_AREA] + left; @@ -1708,8 +1736,8 @@ required_matrix_height (struct window *w) /* One partially visible line at the top and bottom of the window. */ + 2 - /* 2 for header and mode line. */ - + 2); + /* 3 for tab, header and mode line. */ + + 3); } #endif /* HAVE_WINDOW_SYSTEM */ @@ -1862,6 +1890,7 @@ fake_current_matrices (Lisp_Object window) - r->used[LEFT_MARGIN_AREA] - r->used[RIGHT_MARGIN_AREA]); r->mode_line_p = 0; + r->tab_line_p = 0; } } } @@ -2106,6 +2135,36 @@ adjust_frame_glyphs_for_window_redisplay (struct frame *f) } #endif +#if defined (HAVE_WINDOW_SYSTEM) + { + /* Allocate/ reallocate matrices of the tab bar window. If we + don't have a tab bar window yet, make one. */ + struct window *w; + if (NILP (f->tab_bar_window)) + { + Lisp_Object frame; + fset_tab_bar_window (f, make_window ()); + w = XWINDOW (f->tab_bar_window); + XSETFRAME (frame, f); + wset_frame (w, frame); + w->pseudo_window_p = 1; + } + else + w = XWINDOW (f->tab_bar_window); + + w->pixel_left = 0; + w->left_col = 0; + w->pixel_top = FRAME_MENU_BAR_HEIGHT (f); + w->top_line = FRAME_MENU_BAR_LINES (f); + w->total_cols = FRAME_TOTAL_COLS (f); + w->pixel_width = (FRAME_PIXEL_WIDTH (f) + - 2 * FRAME_INTERNAL_BORDER_WIDTH (f)); + w->total_lines = FRAME_TAB_BAR_LINES (f); + w->pixel_height = FRAME_TAB_BAR_HEIGHT (f); + allocate_matrices_for_window_redisplay (w); + } +#endif + #if defined (HAVE_WINDOW_SYSTEM) && ! defined (HAVE_EXT_TOOL_BAR) { /* Allocate/ reallocate matrices of the tool bar window. If we @@ -2125,8 +2184,8 @@ adjust_frame_glyphs_for_window_redisplay (struct frame *f) w->pixel_left = 0; w->left_col = 0; - w->pixel_top = FRAME_MENU_BAR_HEIGHT (f); - w->top_line = FRAME_MENU_BAR_LINES (f); + w->pixel_top = FRAME_MENU_BAR_HEIGHT (f) + FRAME_TAB_BAR_HEIGHT (f); + w->top_line = FRAME_MENU_BAR_LINES (f) + FRAME_TAB_BAR_LINES (f); w->total_cols = FRAME_TOTAL_COLS (f); w->pixel_width = (FRAME_PIXEL_WIDTH (f) - 2 * FRAME_INTERNAL_BORDER_WIDTH (f)); @@ -2188,6 +2247,18 @@ free_glyphs (struct frame *f) } #endif +#if defined (HAVE_WINDOW_SYSTEM) + /* Free the tab bar window and its glyph matrices. */ + if (!NILP (f->tab_bar_window)) + { + struct window *w = XWINDOW (f->tab_bar_window); + free_glyph_matrix (w->desired_matrix); + free_glyph_matrix (w->current_matrix); + w->desired_matrix = w->current_matrix = NULL; + fset_tab_bar_window (f, Qnil); + } +#endif + #if defined (HAVE_WINDOW_SYSTEM) && ! defined (HAVE_EXT_TOOL_BAR) /* Free the tool bar window and its glyph matrices. */ if (!NILP (f->tool_bar_window)) @@ -3082,6 +3153,29 @@ update_frame (struct frame *f, bool force_p, bool inhibit_hairy_id_p) update_window (XWINDOW (f->menu_bar_window), true); #endif +#if defined (HAVE_WINDOW_SYSTEM) + /* Update the tab-bar window, if present. */ + if (WINDOWP (f->tab_bar_window)) + { + struct window *w = XWINDOW (f->tab_bar_window); + + /* Update tab-bar window. */ + if (w->must_be_updated_p) + { + Lisp_Object tem; + + update_window (w, true); + w->must_be_updated_p = false; + + /* Swap tab-bar strings. We swap because we want to + reuse strings. */ + tem = f->current_tab_bar_string; + fset_current_tab_bar_string (f, f->desired_tab_bar_string); + fset_desired_tab_bar_string (f, tem); + } + } +#endif + #if defined (HAVE_WINDOW_SYSTEM) && ! defined (HAVE_EXT_TOOL_BAR) /* Update the tool-bar window, if present. */ if (WINDOWP (f->tool_bar_window)) @@ -3408,6 +3502,7 @@ update_window (struct window *w, bool force_p) { struct glyph_row *row, *end; struct glyph_row *mode_line_row; + struct glyph_row *tab_line_row; struct glyph_row *header_line_row; int yb; bool changed_p = 0, mouse_face_overwritten_p = 0; @@ -3420,6 +3515,16 @@ update_window (struct window *w, bool force_p) row = MATRIX_ROW (desired_matrix, 0); end = MATRIX_MODE_LINE_ROW (desired_matrix); + /* Take note of the tab line, if there is one. We will + update it below, after updating all of the window's lines. */ + if (row->mode_line_p && row->tab_line_p) + { + tab_line_row = row; + ++row; + } + else + tab_line_row = NULL; + /* Take note of the header line, if there is one. We will update it below, after updating all of the window's lines. */ if (row->mode_line_p) @@ -3449,7 +3554,8 @@ update_window (struct window *w, bool force_p) /* Try reusing part of the display by copying. */ if (row < end && !desired_matrix->no_scrolling_p) { - int rc = scrolling_window (w, header_line_row != NULL); + int rc = scrolling_window (w, (tab_line_row != NULL ? 1 : 0) + + (header_line_row != NULL ? 1 : 0)); if (rc < 0) { /* All rows were found to be equal. */ @@ -3501,13 +3607,22 @@ update_window (struct window *w, bool force_p) set_cursor: + /* Update the tab line after scrolling because a new tab + line would otherwise overwrite lines at the top of the window + that can be scrolled. */ + if (tab_line_row && tab_line_row->enabled_p) + { + tab_line_row->y = 0; + update_window_line (w, 0, &mouse_face_overwritten_p); + } + /* Update the header line after scrolling because a new header line would otherwise overwrite lines at the top of the window that can be scrolled. */ if (header_line_row && header_line_row->enabled_p) { - header_line_row->y = 0; - update_window_line (w, 0, &mouse_face_overwritten_p); + header_line_row->y = tab_line_row ? CURRENT_TAB_LINE_HEIGHT (w) : 0; + update_window_line (w, tab_line_row ? 1 : 0, &mouse_face_overwritten_p); } /* Fix the appearance of overlapping/overlapped rows. */ @@ -4178,7 +4293,7 @@ add_row_entry (struct glyph_row *row) 1 if we did scroll. */ static int -scrolling_window (struct window *w, bool header_line_p) +scrolling_window (struct window *w, int tab_line_p) { struct glyph_matrix *desired_matrix = w->desired_matrix; struct glyph_matrix *current_matrix = w->current_matrix; @@ -4191,7 +4306,7 @@ scrolling_window (struct window *w, bool header_line_p) struct redisplay_interface *rif = FRAME_RIF (XFRAME (WINDOW_FRAME (w))); /* Skip over rows equal at the start. */ - for (i = header_line_p; i < current_matrix->nrows - 1; ++i) + for (i = tab_line_p; i < current_matrix->nrows - 1; ++i) { struct glyph_row *d = MATRIX_ROW (desired_matrix, i); struct glyph_row *c = MATRIX_ROW (current_matrix, i); @@ -5318,7 +5433,8 @@ buffer_posn_from_coords (struct window *w, int *x, int *y, struct display_pos *p start position, i.e. it excludes the header-line row, but MATRIX_ROW includes the header-line row. Adjust for a possible header-line row. */ - it_vpos = it.vpos + window_wants_header_line (w); + it_vpos = it.vpos + window_wants_header_line (w) + + window_wants_tab_line (w); if (it_vpos < w->current_matrix->nrows && (row = MATRIX_ROW (w->current_matrix, it_vpos), row->enabled_p)) @@ -5382,6 +5498,8 @@ mode_line_string (struct window *w, enum window_part part, if (part == ON_MODE_LINE) row = MATRIX_MODE_LINE_ROW (w->current_matrix); + else if (part == ON_TAB_LINE) + row = MATRIX_TAB_LINE_ROW (w->current_matrix); else row = MATRIX_HEADER_LINE_ROW (w->current_matrix); y0 = *y - row->y; @@ -5563,7 +5681,8 @@ handle_window_change_signal (int sig) structures now. Let that be done later outside of the signal handler. */ change_frame_size (XFRAME (frame), width, - height - FRAME_MENU_BAR_LINES (XFRAME (frame)), + height - FRAME_MENU_BAR_LINES (XFRAME (frame)) + - FRAME_TAB_BAR_LINES (XFRAME (frame)), 0, 1, 0, 0); } } @@ -6243,7 +6362,8 @@ init_display_interactive (void) change_frame_size (XFRAME (selected_frame), FrameCols (t->display_info.tty), FrameRows (t->display_info.tty) - - FRAME_MENU_BAR_LINES (f), 0, 0, 1, 0); + - FRAME_MENU_BAR_LINES (f) + - FRAME_TAB_BAR_LINES (f), 0, 0, 1, 0); /* Delete the initial terminal. */ if (--initial_terminal->reference_count == 0

index 1d42d0cb4d..d72dfec0cf 100644

--- a/

+++ b/ diff --git a/src/frame.c b/src/frame.cindex 1d42d0cb4d..d72dfec0cf 100644--- a/ src/frame.c +++ b/ src/frame.c @@ -69,6 +69,9 @@ static struct frame *last_nonminibuf_frame; /* False means there are no visible garbaged frames. */ bool frame_garbaged; +/* The default tab bar height for future frames. */ +int frame_default_tab_bar_height; + /* The default tool bar height for future frames. */ #ifdef HAVE_EXT_TOOL_BAR enum { frame_default_tool_bar_height = 0 }; @@ -230,6 +233,35 @@ set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval) 0, 1, 0, 0); } } + +static void +set_tab_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval) +{ + int nlines; + int olines = FRAME_TAB_BAR_LINES (f); + + /* Right now, tab bars don't work properly in minibuf-only frames; + most of the commands try to apply themselves to the minibuffer + frame itself, and get an error because you can't switch buffers + in or split the minibuffer window. */ + if (FRAME_MINIBUF_ONLY_P (f)) + return; + + if (TYPE_RANGED_FIXNUMP (int, value)) + nlines = XFIXNUM (value); + else + nlines = 0; + + if (nlines != olines) + { + windows_or_buffers_changed = 14; + FRAME_TAB_BAR_LINES (f) = nlines; + FRAME_TAB_BAR_HEIGHT (f) = nlines * FRAME_LINE_HEIGHT (f); + change_frame_size (f, FRAME_COLS (f), + FRAME_LINES (f) + olines - nlines, + 0, 1, 0, 0); + } +} Lisp_Object Vframe_list; @@ -379,6 +411,7 @@ frame_windows_min_size (Lisp_Object frame, Lisp_Object horizontal, if ((FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)) && NILP (horizontal)) { int min_height = (FRAME_MENU_BAR_LINES (f) + + FRAME_TAB_BAR_LINES (f) + FRAME_WANTS_MODELINE_P (f) + 2); /* one text line and one echo-area line */ if (retval < min_height) @@ -719,6 +752,15 @@ adjust_frame_size (struct frame *f, int new_width, int new_height, int inhibit, if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f)) FrameCols (FRAME_TTY (f)) = new_cols; +#if defined (HAVE_WINDOW_SYSTEM) + if (WINDOWP (f->tab_bar_window)) + { + XWINDOW (f->tab_bar_window)->pixel_width = new_windows_width; + XWINDOW (f->tab_bar_window)->total_cols + = new_windows_width / unit_width; + } +#endif + #if defined (HAVE_WINDOW_SYSTEM) && ! defined (HAVE_EXT_TOOL_BAR) if (WINDOWP (f->tool_bar_window)) { @@ -838,6 +880,8 @@ make_frame (bool mini_p) f->after_make_frame = false; f->inhibit_horizontal_resize = false; f->inhibit_vertical_resize = false; + f->tab_bar_redisplayed = false; + f->tab_bar_resized = false; f->tool_bar_redisplayed = false; f->tool_bar_resized = false; f->column_width = 1; /* !FRAME_WINDOW_P value. */ @@ -856,6 +900,7 @@ make_frame (bool mini_p) f->no_accept_focus = false; f->z_group = z_group_none; f->tooltip = false; + f->last_tab_bar_item = -1; #ifndef HAVE_EXT_TOOL_BAR f->last_tool_bar_item = -1; #endif @@ -1084,6 +1129,9 @@ make_initial_frame (void) /* The default value of menu-bar-mode is t. */ set_menu_bar_lines (f, make_fixnum (1), Qnil); + /* The default value of tab-bar-mode is nil. */ + set_tab_bar_lines (f, make_fixnum (0), Qnil); + /* Allocate glyph matrices. */ adjust_frame_glyphs (f); @@ -1142,9 +1190,13 @@ make_terminal_frame (struct terminal *terminal) #endif FRAME_MENU_BAR_LINES (f) = NILP (Vmenu_bar_mode) ? 0 : 1; - FRAME_LINES (f) = FRAME_LINES (f) - FRAME_MENU_BAR_LINES (f); + FRAME_TAB_BAR_LINES (f) = NILP (Vtab_bar_mode) ? 0 : 1; + FRAME_LINES (f) = FRAME_LINES (f) - FRAME_MENU_BAR_LINES (f) + - FRAME_TAB_BAR_LINES (f); FRAME_MENU_BAR_HEIGHT (f) = FRAME_MENU_BAR_LINES (f) * FRAME_LINE_HEIGHT (f); - FRAME_TEXT_HEIGHT (f) = FRAME_TEXT_HEIGHT (f) - FRAME_MENU_BAR_HEIGHT (f); + FRAME_TAB_BAR_HEIGHT (f) = FRAME_TAB_BAR_LINES (f) * FRAME_LINE_HEIGHT (f); + FRAME_TEXT_HEIGHT (f) = FRAME_TEXT_HEIGHT (f) - FRAME_MENU_BAR_HEIGHT (f) + - FRAME_TAB_BAR_HEIGHT (f); /* Set the top frame to the newly created frame. */ if (FRAMEP (FRAME_TTY (f)->top_frame) @@ -1266,7 +1318,8 @@ affects all frames on the same terminal device. */) { int width, height; get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height); - adjust_frame_size (f, width, height - FRAME_MENU_BAR_LINES (f), + adjust_frame_size (f, width, height - FRAME_MENU_BAR_LINES (f) + - FRAME_TAB_BAR_LINES (f), 5, 0, Qterminal_frame); } @@ -3071,6 +3124,8 @@ store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val) { if (EQ (prop, Qmenu_bar_lines)) set_menu_bar_lines (f, val, make_fixnum (FRAME_MENU_BAR_LINES (f))); + else if (EQ (prop, Qtab_bar_lines)) + set_tab_bar_lines (f, val, make_fixnum (FRAME_TAB_BAR_LINES (f))); else if (EQ (prop, Qname)) set_term_frame_name (f, val); } @@ -3166,6 +3221,8 @@ If FRAME is omitted or nil, return information on the currently selected frame. Lisp_Object lines; XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f)); store_in_alist (&alist, Qmenu_bar_lines, lines); + XSETFASTINT (lines, FRAME_TAB_BAR_LINES (f)); + store_in_alist (&alist, Qtab_bar_lines, lines); } return alist; @@ -3695,6 +3752,7 @@ static const struct frame_parm_table frame_parms[] = {"vertical-scroll-bars", SYMBOL_INDEX (Qvertical_scroll_bars)}, {"horizontal-scroll-bars", SYMBOL_INDEX (Qhorizontal_scroll_bars)}, {"visibility", SYMBOL_INDEX (Qvisibility)}, + {"tab-bar-lines", SYMBOL_INDEX (Qtab_bar_lines)}, {"tool-bar-lines", SYMBOL_INDEX (Qtool_bar_lines)}, {"scroll-bar-foreground", SYMBOL_INDEX (Qscroll_bar_foreground)}, {"scroll-bar-background", SYMBOL_INDEX (Qscroll_bar_background)}, @@ -4450,6 +4508,8 @@ gui_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval) #ifdef HAVE_X_WINDOWS store_frame_param (f, Qfont_parameter, font_param); #endif + /* Recalculate tabbar height. */ + f->n_tab_bar_rows = 0; /* Recalculate toolbar height. */ f->n_tool_bar_rows = 0; @@ -5390,8 +5450,8 @@ On Nextstep, this just calls `ns-parse-geometry'. */) #define DEFAULT_COLS 80 long -gui_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p, - int *x_width, int *x_height) +gui_figure_window_size (struct frame *f, Lisp_Object parms, bool tabbar_p, + bool toolbar_p, int *x_width, int *x_height) { Lisp_Object height, width, user_size, top, left, user_position; long window_prompting = 0; @@ -5411,6 +5471,36 @@ gui_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p, f->top_pos = 0; f->left_pos = 0; + /* Calculate a tab bar height so that the user gets a text display + area of the size he specified with -g or via .Xdefaults. Later + changes of the tab bar height don't change the frame size. This + is done so that users can create tall Emacs frames without having + to guess how tall the tab bar will get. */ + if (tabbar_p && FRAME_TAB_BAR_LINES (f)) + { + if (frame_default_tab_bar_height) + FRAME_TAB_BAR_HEIGHT (f) = frame_default_tab_bar_height; + else + { + int margin, relief; + + relief = (tab_bar_button_relief < 0 + ? DEFAULT_TAB_BAR_BUTTON_RELIEF + : min (tab_bar_button_relief, 1000000)); + + if (RANGED_FIXNUMP (1, Vtab_bar_button_margin, INT_MAX)) + margin = XFIXNAT (Vtab_bar_button_margin); + else if (CONSP (Vtab_bar_button_margin) + && RANGED_FIXNUMP (1, XCDR (Vtab_bar_button_margin), INT_MAX)) + margin = XFIXNAT (XCDR (Vtab_bar_button_margin)); + else + margin = 0; + + FRAME_TAB_BAR_HEIGHT (f) + = DEFAULT_TAB_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief; + } + } + /* Calculate a tool bar height so that the user gets a text display area of the size he specified with -g or via .Xdefaults. Later changes of the tool bar height don't change the frame size. This @@ -5837,6 +5927,7 @@ syms_of_frame (void) DEFSYM (Qtitle_bar_size, "title-bar-size"); DEFSYM (Qmenu_bar_external, "menu-bar-external"); DEFSYM (Qmenu_bar_size, "menu-bar-size"); + DEFSYM (Qtab_bar_size, "tab-bar-size"); DEFSYM (Qtool_bar_external, "tool-bar-external"); DEFSYM (Qtool_bar_size, "tool-bar-size"); /* The following are used for frame_size_history. */ @@ -5860,7 +5951,9 @@ syms_of_frame (void) DEFSYM (Qx_net_wm_state, "x-net-wm-state"); DEFSYM (Qx_handle_net_wm_state, "x-handle-net-wm-state"); DEFSYM (Qtb_size_cb, "tb-size-cb"); + DEFSYM (Qupdate_frame_tab_bar, "update-frame-tab-bar"); DEFSYM (Qupdate_frame_tool_bar, "update-frame-tool-bar"); + DEFSYM (Qfree_frame_tab_bar, "free-frame-tab-bar"); DEFSYM (Qfree_frame_tool_bar, "free-frame-tool-bar"); DEFSYM (Qx_set_menu_bar_lines, "x-set-menu-bar-lines"); DEFSYM (Qchange_frame_size, "change-frame-size"); @@ -5910,6 +6003,7 @@ syms_of_frame (void) DEFSYM (Qscroll_bar_width, "scroll-bar-width"); DEFSYM (Qsticky, "sticky"); DEFSYM (Qtitle, "title"); + DEFSYM (Qtab_bar_lines, "tab-bar-lines"); DEFSYM (Qtool_bar_lines, "tool-bar-lines"); DEFSYM (Qtool_bar_position, "tool-bar-position"); DEFSYM (Qunsplittable, "unsplittable"); @@ -6071,6 +6165,14 @@ either customize it (see the info node `Easy Customization') or call the function `menu-bar-mode'. */); Vmenu_bar_mode = Qt; + DEFVAR_LISP ("tab-bar-mode", Vtab_bar_mode, + doc: /* Non-nil if Tab-Bar mode is enabled. +See the command `tab-bar-mode' for a description of this minor mode. +Setting this variable directly does not take effect; +either customize it (see the info node `Easy Customization') +or call the function `tab-bar-mode'. */); + Vtab_bar_mode = Qnil; + DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode, doc: /* Non-nil if Tool-Bar mode is enabled. See the command `tool-bar-mode' for a description of this minor mode. @@ -6200,7 +6302,7 @@ any of the parameters listed above, Emacs may try to enlarge the frame even if this option is non-nil. */); #if defined (HAVE_WINDOW_SYSTEM) #if defined (USE_LUCID) || defined (USE_MOTIF) || defined (HAVE_NTGUI) - frame_inhibit_implied_resize = list1 (Qtool_bar_lines); + frame_inhibit_implied_resize = list2 (Qtab_bar_lines, Qtool_bar_lines); #else frame_inhibit_implied_resize = Qnil; #endif

index fa45a32d6b..1b21cc6284 100644

--- a/

+++ b/ diff --git a/src/frame.h b/src/frame.hindex fa45a32d6b..1b21cc6284 100644--- a/ src/frame.h +++ b/ src/frame.h @@ -181,6 +181,15 @@ struct frame Lisp_Object menu_bar_window; #endif +#if defined (HAVE_WINDOW_SYSTEM) + /* A window used to display the tab-bar of a frame. */ + Lisp_Object tab_bar_window; + + /* Desired and current contents displayed in that window. */ + Lisp_Object desired_tab_bar_string; + Lisp_Object current_tab_bar_string; +#endif + #if defined (HAVE_WINDOW_SYSTEM) && ! defined (HAVE_EXT_TOOL_BAR) /* A window used to display the tool-bar of a frame. */ Lisp_Object tool_bar_window; @@ -201,6 +210,9 @@ struct frame Lisp_Object font_data; #endif + /* Desired and current tab-bar items. */ + Lisp_Object tab_bar_items; + /* Desired and current tool-bar items. */ Lisp_Object tool_bar_items; /* tool_bar_items should be the last Lisp_Object member. */ @@ -208,6 +220,11 @@ struct frame /* Cache of realized faces. */ struct face_cache *face_cache; +#if defined (HAVE_WINDOW