Subject: Re: bug#78881: [PATCH] New command 'toggle-mode-line-visibility'

From: Elijah Gabe Pérez <[email-masked]>
Date: Wed, 25 Jun 2025 13:00:35 -0600

Eli Zaretskii <[email-masked]> writes:

[...]

>> >> +The mode line is hidden from every major mode change in current buffer.
>> >
>> > This sentence confused me.  What did you mean to say here?
>> 
>> e.g. If you call `toggle-mode-line-visibility` in the scratch buffer and
>> later call `text-mode` in the same buffer, the mode line will become
>> visible again, which is not convenient since this command is meant to
>> enable/disable the mode line per buffer, not per major mode.
>
> So you want to say this:
>
>   Changing the major mode will not display the hidden mode line.
>
> Or maybe simply remove this part: why would someone assume that
> another major mode will override this?  If they won't expect that,
> you don't have to explain that it won't happen.

Agree, I've removed that part.

>> +(define-minor-mode toggle-mode-line-visibility
>> +  "Toggle mode line visibility in current buffer.
>
> I don't see why "toggle" should be in the name.  How about
> mode-line-invisible-mode ?

Fine, I've renamed it to `mode-line-invisible-mode`.

> or hide-mode-line-mode ?

I would have liked to use that name, but there is already a package that
has it.  So I prefer to avoid potential bugs due to the name.

>From 01f04d64e1faa5d66fe3fdaf43d4794f8c7985f3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?El=C3=ADas=20Gabriel=20P=C3=A9rez?= <[email-masked]>
Date: Mon, 23 Jun 2025 12:50:28 -0600
Subject: [PATCH] New command 'mode-line-invisible-mode'

This new command allows hide the mode line in the current
buffer.  (Bug#78881)

* doc/emacs/display.texi (Optional Mode Line): Document feature.
* etc/NEWS: Announce changes.
* lisp/bindings.el (mode-line-invisible--buf-state): New buffer
local variable.
(mode-line-invisible-mode): New minor mode.
---
 doc/emacs/display.texi |  8 ++++++++
 etc/NEWS               |  5 +++++
 lisp/bindings.el       | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+)

diff --git a/doc/emacs/display.texi b/doc/emacs/display.texi
index ad496b5b1cd..c3bdf410c70 100644
--- a/doc/emacs/display.texi
+++ b/doc/emacs/display.texi
@@ -1826,6 +1826,14 @@ Optional Mode Line
 and Emacs will hide some minor mode indicators on the mode line by
 collapsing them into a single clickable button.
 
+@findex mode-line-invisible-mode
+  By default, most buffers display a mode line, however not in many
+cases the mode line may be useful, you can use the command @kbd{M-x
+mode-line-invisible-mode} to hide the mode line in the current buffer,
+the mode line remains hidden until this command is called again.  To
+always hide the mode line when entering to a major mode, add
+@code{mode-line-invisible-mode} to a hook @xref{Hooks}.
+
 @node Text Display
 @section How Text Is Displayed
 @cindex characters (in text)
diff --git a/etc/NEWS b/etc/NEWS
index f7aebdf538f..003bad3d2e0 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -346,6 +346,11 @@ This option allows changing or removing the delimiters shown around
 the major mode and list of minor modes in the mode line.  The default
 retains the existing behavior of inserting parentheses.
 
++++
+*** New minor mode 'mode-line-invisible-mode'.
+This command hide temporarily the mode line in current buffer until
+'mode-line-invisible-mode' is called again.
+
 ** Tab Bars and Tab Lines
 
 ---
diff --git a/lisp/bindings.el b/lisp/bindings.el
index 8b021a05ce2..007c096edb0 100644
--- a/lisp/bindings.el
+++ b/lisp/bindings.el
@@ -56,6 +56,38 @@ mode-line-widen
     (widen)
     (force-mode-line-update)))
 
+;; Variable used by `mode-line-invisible-mode' for
+;; store mode-line value in current buffer.
+(defvar-local mode-line-invisible--buf-state)
+
+(define-minor-mode mode-line-invisible-mode
+  "Hide temporarily the mode line in the current buffer.
+Hide the mode line in current buffer until this minor mode is called
+again."
+  :global nil
+  (if mode-line-invisible-mode
+      (progn
+        (add-hook 'after-change-major-mode-hook #'mode-line-invisible-mode nil t)
+        (setq mode-line-invisible--buf-state
+              (buffer-local-set-state mode-line-format nil)))
+
+    (remove-hook 'after-change-major-mode-hook #'mode-line-invisible-mode t)
+
+    (when mode-line-invisible--buf-state
+      (setq mode-line-invisible--buf-state
+            (buffer-local-restore-state mode-line-invisible--buf-state)))
+
+    ;; Display a mode line if buffer does not have one by default
+    (unless mode-line-format
+      (setq-local mode-line-format (default-value 'mode-line-format)))
+
+    ;; Update mode line
+    (when (called-interactively-p 'any)
+      (force-mode-line-update))))
+
+(put 'mode-line-invisible--buf-state 'permanent-local t)
+(put 'mode-line-invisible-mode 'permanent-local-hook t)
+
 (defvar mode-line-input-method-map
   (let ((map (make-sparse-keymap)))
     (define-key map [mode-line mouse-2]
-- 
2.49.0

-- 
                                          - E.G via GNU Emacs and Org.