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

From: Elijah Gabe Pérez <[email-masked]>
Date: Sat, 05 Jul 2025 14:45:12 -0600

Eli Zaretskii <[email-masked]> writes:

> Sorry, I needed to revert that, because these changes failed the
> bootstrap.
>
> We cannot call define-minor-mode in bindings.el, because bindings.el
> is loaded by loadup.el before loaddefs.el, and so define-minor-mode is
> not yet known as an autoloaded macro.
>
> One solution is to move the code to simple.el instead.

Fine, I've moved it to simple.el, see patch below:

>From 20a7ae98dd5f4e7fd83f4c0dfc6f5dddaeee8913 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/simple.el (mode-line-invisible--buf-state): New buffer
local variable.
(mode-line-invisible-mode): New minor mode.
---
 doc/emacs/display.texi |  8 ++++++++
 etc/NEWS               |  7 +++++++
 lisp/simple.el         | 31 +++++++++++++++++++++++++++++++
 3 files changed, 46 insertions(+)

diff --git a/doc/emacs/display.texi b/doc/emacs/display.texi
index ad496b5b1cd..8da0495f531 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, but if the mode line is
+not useful in a buffer, you can use the command @w{@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 (@pxref{Hooks}).
+
 @node Text Display
 @section How Text Is Displayed
 @cindex characters (in text)
diff --git a/etc/NEWS b/etc/NEWS
index 3703f5b3dbf..2e3e6d09791 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -353,6 +353,13 @@ 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 minor mode makes the mode-line of the current buffer invisible.
+The command 'mode-line-invisible-mode' toggles the visibility of the
+current-buffer's mode-line.  The default is to show the mode line of
+every buffer.
+
 ** Tab Bars and Tab Lines
 
 ---
diff --git a/lisp/simple.el b/lisp/simple.el
index fa173b26289..f2a66bbfba2 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -9382,6 +9382,37 @@ size-indication-mode
   "Toggle buffer size display in the mode line (Size Indication mode)."
   :global t :group 'mode-line)
 
+(defvar-local mode-line-invisible--buf-state)
+
+(define-minor-mode mode-line-invisible-mode
+  "Toggle the mode-line visibility of the current buffer.
+Hide the mode line if it is shown, and show it if it's hidden."
+  :global nil
+  :group 'mode-line
+  (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)
+
+    ;; Restore buffer mode line if buffer had one by default
+    (when mode-line-invisible--buf-state
+      (setq mode-line-invisible--buf-state
+            (buffer-local-restore-state mode-line-invisible--buf-state)))
+
+    ;; Otherwise display one
+    (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)
+
 (defcustom remote-file-name-inhibit-auto-save nil
   "When nil, `auto-save-mode' will auto-save remote files.
 Any other value means that it will not."
-- 
2.50.0

> Please in the future always test your changes by "make bootstrap", to
> avoid problems of this kind.

Thanks, and sorry for the inconvenience.

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