Subject: Re: bug#68765: 30.0.50; Adding window-tool-bar package.

From: Jared Finder <[email-masked]>
Date: Sat, 25 May 2024 12:54:30 -0700

On 2024-05-25 10:03, Eli Zaretskii wrote:
>> Date: Sat, 25 May 2024 08:49:22 -0700
>> From: Jared Finder <[email-masked]>
>> Cc: [email-masked], [email-masked], [email-masked],
>>  [email-masked]
>> 
>> >> +@node Window Tool Bar
>> >> +@cindex mode, Window Tool Bar
>> >
>> > Index entries should preferably use only lower-case letters, to avoid
>> > problems with sorting index entries in different locales.
>> >
>> > In addition, I would rephrase the above index entry to say just
>> >
>> >   @cindex window tool bar
>> 
>> I don't think that fits in with the existing convention.  The 
>> convention
>> appears to be "use mode, Capital Case Name" for specific modes and
>> "mode, lower case" for concepts.  There's 76 other examples of 
>> "@cindex
>> mode," in the Emacs manual already, the majority of which follow that
>> convention.
>> 
>> The only examples I could find not following the convention are: 
>> "mode,
>> archive", "mode, tar", "mode, display-fill-column-indicator".
> 
> Nevertheless, I stand by what I wrote.  The examples which you quote,
> whether they are a few or not, are mistakes: letter-case affects
> sorting of index entries in locale-dependent way, so index entries
> that us capital letters will appear in a different order in different
> locales, which is not a good thing.

Ok, I tried to fit into the existing convention but not use upper case 
letters with "@cindex mode, window tool bar".  Let me know if that's not 
appropriate.

>> I will try to redescribe it.  I have a typo in the existing 
>> description.
>>   Change "all windows" to "each window".  The idea is that each window
>> gets its own tool bar *inside the window*, specifically on the 
>> window's
>> tab line.  Ideally I think I would just show a picture (see attached
>> image), but I see very few pictures in any of the Emacs manuals and 
>> none
>> of them show up in the HTML output at
>> https://www.gnu.org/software/emacs/manual/, only in the PDF.
> 
> I don't think there were images in our manuals in previous versions,
> which is why they don't appear in HTML.
> 
> Pictures have a disadvantage in that they cannot be displayed on TTY
> frames, so a picture that cannot be replaced by some "ASCII art"
> generally means the reader on a TTY frame will be at a disadvantage.

That's what I was concerned about.  Please let me know if this updated 
text is clear enough.

> I will wait for the next version to see if my questions are now
> answered or we need to discuss them further.

New patch attached.  Feedback welcome.

   -- MJF

From de54c4026158520244d0418c221e4e29694ee6fb Mon Sep 17 00:00:00 2001
From: Jared Finder <[email-masked]>
Date: Mon, 20 May 2024 21:59:14 -0700
Subject: [PATCH] Adding documentation for window-tool-bar (bug#68765)

* doc/emacs/emacs.texi (Top):
* doc/emacs/frames.texi (Tool Bars):
* doc/emacs/glossary.texi (Glossary):
* doc/emacs/modes.texi (Minor Modes): Mention Window Tool Bar
and add xref.
* doc/emacs/windows.texi (Windows, Tab Line): New documentation.
* doc/lispref/elisp.texi (Top):
* doc/lispref/modes.texi (Mode Line Format, Mode Line Basics)
(Mode Line Data): Mention Tab Lines and add xref.
(Tab Lines): New documentation.
* etc/NEWS: Mention newly added variable
'tool-bar-always-show-default' and new package 'window-tool-bar'
---
 doc/emacs/emacs.texi    |  1 +
 doc/emacs/frames.texi   | 14 +++++++----
 doc/emacs/glossary.texi | 10 ++++----
 doc/emacs/modes.texi    |  4 ++++
 doc/emacs/windows.texi  | 42 ++++++++++++++++++++++++++++++++
 doc/lispref/elisp.texi  |  1 +
 doc/lispref/modes.texi  | 53 ++++++++++++++++++++++++++++++-----------
 etc/NEWS                | 14 +++++++++++
 8 files changed, 117 insertions(+), 22 deletions(-)

diff --git a/doc/emacs/emacs.texi b/doc/emacs/emacs.texi
index 7d77f13ab21..8246041fb95 100644
--- a/doc/emacs/emacs.texi
+++ b/doc/emacs/emacs.texi
@@ -529,6 +529,7 @@ Top
 * Temporary Displays::  Displaying non-editable buffers.
 * Window Convenience::  Convenience functions for window handling.
 * Tab Line::            Window tab line.
+* Window Tool Bar::     A tool bar that is attached to windows.
 
 Displaying a Buffer in a Window
 
diff --git a/doc/emacs/frames.texi b/doc/emacs/frames.texi
index 6c62fde4ffb..8028a516e66 100644
--- a/doc/emacs/frames.texi
+++ b/doc/emacs/frames.texi
@@ -1295,16 +1295,22 @@ Menu Bars
 @node Tool Bars
 @section Tool Bars
 @cindex tool bar mode
+@cindex tool bar, attached to frame
 @cindex mode, Tool Bar
 @cindex icons, toolbar
 
-  On graphical displays, Emacs puts a @dfn{tool bar} at the top of
-each frame, just below the menu bar.  This is a row of icons which you
-can click on with the mouse to invoke various commands.
+  On graphical displays, Emacs puts a @dfn{tool bar} at the top of each
+frame, just below the menu bar.  This is a row of icons which you can
+click on with the mouse to invoke various commands.  Emacs can also
+optionally display a tool bar at the top of each window (@pxref{Window
+Tool Bar}).
 
+@vindex tool-bar-always-show-default
   The global (default) tool bar contains general commands.  Some major
 modes define their own tool bars; whenever a buffer with such a major
-mode is current, the mode's tool bar replaces the global tool bar.
+mode is current, the mode's tool bar replaces the global tool bar.  To
+prevent this replacement from happening, customize the variable
+@code{tool-bar-always-show-default}.
 
 @findex tool-bar-mode
 @vindex tool-bar-mode
diff --git a/doc/emacs/glossary.texi b/doc/emacs/glossary.texi
index 344e4831f36..b30e1d789fc 100644
--- a/doc/emacs/glossary.texi
+++ b/doc/emacs/glossary.texi
@@ -1436,10 +1436,12 @@ Glossary
 for your favorite set of faces (q.v.).
 
 @item Tool Bar
-The tool bar is a line (sometimes multiple lines) of icons at the top
-of an Emacs frame.  Clicking on one of these icons executes a command.
-You can think of this as a graphical relative of the menu bar (q.v.).
-@xref{Tool Bars}.
+The tool bar is a line (sometimes multiple lines) of icons at the top of
+an Emacs frame.  Clicking on one of these icons executes a command.  You
+can think of this as a graphical relative of the menu bar (q.v.).
+@xref{Tool Bars}.  There is also a window tool bar that behaves
+similarly, but is at the top of an Emacs window.  @xref{Window Tool
+Bar}.
 
 @anchor{Glossary---Tooltips}
 @item Tooltips
diff --git a/doc/emacs/modes.texi b/doc/emacs/modes.texi
index 2776dc72a27..253042b28a3 100644
--- a/doc/emacs/modes.texi
+++ b/doc/emacs/modes.texi
@@ -295,6 +295,10 @@ Minor Modes
 but the tool bar is only displayed on graphical terminals.  @xref{Tool
 Bars}.
 
+@item
+Window Tool Bar mode gives windows a tool bar when it is different from
+the default tool bar.  @xref{Window Tool Bar}.
+
 @item
 Tab Bar mode gives each frame a tab bar.  @xref{Tab Bars}.
 
diff --git a/doc/emacs/windows.texi b/doc/emacs/windows.texi
index ad2225b5922..b7193593557 100644
--- a/doc/emacs/windows.texi
+++ b/doc/emacs/windows.texi
@@ -22,6 +22,7 @@ Windows
 * Displaying Buffers::  How Emacs picks a window for displaying a buffer.
 * Window Convenience::  Convenience functions for window handling.
 * Tab Line::            Window tab line.
+* Window Tool Bar::     A tool bar that is attached to windows.
 @end menu
 
 @node Basic Window
@@ -689,3 +690,44 @@ Tab Line
 switch between window configurations containing several windows with buffers,
 tabs on the Tab Line at the top of each window are used to switch
 between buffers in the window.
+
+
+@node Window Tool Bar
+@cindex window tool bar
+@cindex mode, window tool bar
+@cindex tool bar, attached to window
+
+@findex global-window-tool-bar-mode
+  The command @code{global-window-tool-bar-mode} toggles the display of
+a tool bar at the top of each window.  When enabled, multiple windows
+can display their own tool bar simultaneously.  To conserve space, a
+window tool bar is only shown if the tool bar for that window's current
+buffer is different from the global (default) tool bar.  The most common
+way a buffer has a different tool bar is due to its major mode, so you
+can think of the window tool bar as showing a major mode's tool bar if
+it exists.
+
+@findex window-tool-bar-mode
+If you want to toggle the display of a window tool bar for only some
+buffers, run the command @code{window-tool-bar-mode}.  The window tool
+bar will then only appear at the top of any window displaying that
+buffer.  This is useful to put in a hook.  For example, if you want the
+window tool bar to appear only for buffers that do not represent files
+and have a custom tool bar, you could add the following code to your
+init file (@pxref{Init File}):
+
+@example
+(add-hook 'special-mode-hook 'window-tool-bar-mode)
+@end example
+
+Emacs can also display a single tool bar at the top of frames
+(@pxref{Tool Bars}).  When showing a tool bar at the top of frames as
+well as windows, you may want to have the frame tool bar not change
+based on the current buffer's major mode.  This can be done by
+customizing the variable @code{tool-bar-always-show-default}.
+
+Note that the window tool bar displays in the same space as the tab
+line, so only one of these can be display at a time unless you customize
+the value of @code{tab-line-format} in Lisp.  In this case, add
+@code{(:eval (window-tool-bar-strng))} to @code{tab-line-format}.
+@xref{Mode Line Format,,, elisp, The Emacs Lisp Reference Manual}.
diff --git a/doc/lispref/elisp.texi b/doc/lispref/elisp.texi
index 339272d1f05..1059d0dcf61 100644
--- a/doc/lispref/elisp.texi
+++ b/doc/lispref/elisp.texi
@@ -925,6 +925,7 @@ Top
 * %-Constructs::            Putting information into a mode line.
 * Properties in Mode::      Using text properties in the mode line.
 * Header Lines::            Like a mode line, but at the top.
+* Tab Lines::               A line that is above the header line.
 * Emulating Mode Line::     Formatting text as the mode line would.
 
 Font Lock Mode
diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index cf67b319924..6ee1d869fb8 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -2074,14 +2074,14 @@ Mode Line Format
 line at the bottom, which displays status information about the buffer
 displayed in the window.  The mode line contains information about the
 buffer, such as its name, associated file, depth of recursive editing,
-and major and minor modes.  A window can also have a @dfn{header
-line}, which is much like the mode line but appears at the top of the
-window.
+and major and minor modes.  A window can also have a @dfn{header line}
+and a @dfn{tab line}, which are much like the mode line but they appear
+at the top of the window.
 
-  This section describes how to control the contents of the mode line
-and header line.  We include it in this chapter because much of the
-information displayed in the mode line relates to the enabled major and
-minor modes.
+  This section describes how to control the contents of the mode line,
+header line, and tab line.  We include it in this chapter because much
+of the information displayed in the mode line relates to the enabled
+major and minor modes.
 
 @menu
 * Base: Mode Line Basics.       Basic ideas of mode line control.
@@ -2091,6 +2091,7 @@ Mode Line Format
 * %-Constructs::                Putting information into a mode line.
 * Properties in Mode::          Using text properties in the mode line.
 * Header Lines::                Like a mode line, but at the top.
+* Tab Lines::                   A line that is above the header line.
 * Emulating Mode Line::         Formatting text as the mode line would.
 @end menu
 
@@ -2101,11 +2102,13 @@ Mode Line Basics
 variable @code{mode-line-format} (@pxref{Mode Line Top}).  This variable
 holds a @dfn{mode line construct}: a template that controls what is
 displayed on the buffer's mode line.  The value of
-@code{header-line-format} specifies the buffer's header line in the same
-way.  All windows for the same buffer use the same
-@code{mode-line-format} and @code{header-line-format} unless a
-@code{mode-line-format} or @code{header-line-format} parameter has been
-specified for that window (@pxref{Window Parameters}).
+@code{header-line-format} and @code{tab-line-format} specifies the
+buffer's header line and tab line in the same way.  All windows for the
+same buffer use the same @code{mode-line-format},
+@code{header-line-format}, and @code{tab-line-format} unless a
+@code{mode-line-format}, @code{header-line-format}, or
+@code{tab-line-format} parameter has been specified for that window
+(@pxref{Window Parameters}).
 
   For efficiency, Emacs does not continuously recompute each window's
 mode line and header line.  It does so when circumstances appear to call
@@ -2167,8 +2170,8 @@ Mode Line Data
 @dfn{mode line construct}, made up of lists, strings, symbols, and
 numbers kept in buffer-local variables.  Each data type has a specific
 meaning for the mode line appearance, as described below.  The same data
-structure is used for constructing frame titles (@pxref{Frame Titles})
-and header lines (@pxref{Header Lines}).
+structure is used for constructing frame titles (@pxref{Frame Titles}),
+header lines (@pxref{Header Lines}), and tab lines (@pxref{Tab Lines}).
 
   A mode line construct may be as simple as a fixed string of text,
 but it usually specifies how to combine fixed strings with variables'
@@ -2816,6 +2819,28 @@ Header Lines
 header line at once; if it has a mode line, then it does not display a
 header line.
 
+@node Tab Lines
+@subsection Window Tab Lines
+@cindex tab line (of a window)
+@cindex window tab line
+
+  A window can have a @dfn{tab line} at the top.  If both the tab line
+and header line are visible, the tab line appears above the header line.
+The tab line feature works just like the mode line feature, except that
+it's controlled by @code{tab-line-format}:
+
+@defvar tab-line-format
+This variable, local in every buffer, specifies how to display the tab
+line, for windows displaying the buffer.  The format of the value is the
+same as for @code{mode-line-format} (@pxref{Mode Line Data}).  It is
+normally @code{nil}, so that ordinary buffers have no tab line.
+@end defvar
+
+@defun window-tab-line-height &optional window
+This function returns the height in pixels of @var{window}'s tab line.
+@var{window} must be a live window, and defaults to the selected window.
+@end defun
+
 @node Emulating Mode Line
 @subsection Emulating Mode Line Formatting
 
diff --git a/etc/NEWS b/etc/NEWS
index d72ef5b5bef..7b829f5002c 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -240,6 +240,12 @@ window systems other than Nextstep.
 When this minor mode is enabled, buttons representing modifier keys
 are displayed along the tool bar.
 
++++
+** New user option 'tool-bar-always-show-default'.
+This can be set so that the tool bar at the top of a frame does not show
+buffer local customization of the tool bar.  This is convenient when
+using the newly added 'global-window-tool-bar-mode'.
+
 +++
 ** "d" in the mode line now indicates that the window is dedicated.
 Windows have always been able to be dedicated to a specific buffer;
@@ -1877,6 +1883,14 @@ than regular expressions, but less complexity than context-free
 grammars.  The Info manual "(elisp) Parsing Expression Grammars" has
 documentation and examples.
 
++++
+** New package Window-Tool-Bar.
+This provides a new minor mode, 'window-tool-bar-mode'.  When this minor
+mode is enabled, a tool bar is displayed at the top of a window if the
+buffer in the window has a buffer local tool bar, commonly from its
+major mode.  The global minor mode 'global-window-tool-bar-mode' enables
+this minor mode in all buffers.
+
 
 * Incompatible Lisp Changes in Emacs 30.1
 
-- 
2.39.2