Enhance inhibit-message/redisplay and mode-line sections

This commit is contained in:
James Cherti
2025-02-18 15:37:14 -05:00
parent 9b114a91ea
commit 4a5431fb36

View File

@@ -43,13 +43,23 @@ turned on.")
When set to non-nil, Emacs will automatically call `package-initialize' and When set to non-nil, Emacs will automatically call `package-initialize' and
`package-refresh-contents' to set up and update the package system.") `package-refresh-contents' to set up and update the package system.")
(defvar minimal-emacs-inhibit-messages-during-startup nil (defvar minimal-emacs-inhibit-redisplay-during-startup nil
"Suppress startup messages. "Suppress redisplay during startup to improve performance.
This provides a cleaner startup experience and improve startup performance.") This prevents visual updates while Emacs initializes, leading to a cleaner and
faster startup. The tradeoff is that you won't see the progress or activities
during the startup process.")
(defvar minimal-emacs-inhibit-message-during-startup nil
"Suppress startup messages for a cleaner experience.
By disabling startup messages, this slightly enhances performance and provides a
cleaner startup. The tradeoff is that you won't be informed of the progress or
any relevant activities during startup.")
(defvar minimal-emacs-disable-mode-line-during-startup nil (defvar minimal-emacs-disable-mode-line-during-startup nil
"Disable the mode line during startup. "Disable the mode line during startup to improve performance.
This enhances performance and provide a minimalistic appearance.") This reduces visual clutter and slightly enhances startup performance. The
tradeoff is that the mode line is hidden during the startup phase, giving a more
minimalistic appearance during startup.")
(defvar minimal-emacs-user-directory user-emacs-directory (defvar minimal-emacs-user-directory user-emacs-directory
"The default value of the `user-emacs-directory' variable.") "The default value of the `user-emacs-directory' variable.")
@@ -129,12 +139,17 @@ This enhances performance and provide a minimalistic appearance.")
(unless noninteractive (unless noninteractive
(unless minimal-emacs-debug (unless minimal-emacs-debug
;; Suppress redisplay and redraw during startup to avoid delays and (when minimal-emacs-inhibit-redisplay-during-startup
;; prevent flashing an unstyled Emacs frame. ;; Suppress redisplay and redraw during startup to avoid delays and
;; (setq-default inhibit-redisplay t) ; Can cause artifacts ;; prevent flashing an unstyled Emacs frame.
(when minimal-emacs-inhibit-messages-during-startup (defun minimal-emacs--reset-inhibit-redisplay ()
(setq-default inhibit-message t) (setq-default inhibit-redisplay nil)
(remove-hook 'post-command-hook #'minimal-emacs--reset-inhibit-redisplay))
(setq-default inhibit-redisplay t)
(add-hook 'post-command-hook #'minimal-emacs--reset-inhibit-redisplay -100))
(when minimal-emacs-inhibit-message-during-startup
;; Reset the above variables to prevent Emacs from appearing frozen or ;; Reset the above variables to prevent Emacs from appearing frozen or
;; visually corrupted after startup or if a startup error occurs. ;; visually corrupted after startup or if a startup error occurs.
(defun minimal-emacs--reset-inhibit-message () (defun minimal-emacs--reset-inhibit-message ()
@@ -142,31 +157,36 @@ This enhances performance and provide a minimalistic appearance.")
(setq-default inhibit-message nil) (setq-default inhibit-message nil)
(remove-hook 'post-command-hook #'minimal-emacs--reset-inhibit-message)) (remove-hook 'post-command-hook #'minimal-emacs--reset-inhibit-message))
(add-hook 'post-command-hook (setq-default inhibit-message t)
#'minimal-emacs--reset-inhibit-message -100)) (add-hook 'post-command-hook #'minimal-emacs--reset-inhibit-message -100))
(put 'mode-line-format
'initial-value (default-toplevel-value 'mode-line-format))
(when minimal-emacs-disable-mode-line-during-startup (when minimal-emacs-disable-mode-line-during-startup
(put 'mode-line-format 'initial-value
(default-toplevel-value 'mode-line-format))
(setq-default mode-line-format nil) (setq-default mode-line-format nil)
(dolist (buf (buffer-list)) (dolist (buf (buffer-list))
(with-current-buffer buf (with-current-buffer buf
(setq mode-line-format nil))) (setq mode-line-format nil))))
(defun minimal-emacs--startup-load-user-init-file (fn &rest args) (defun minimal-emacs--startup-load-user-init-file (fn &rest args)
"Advice for startup--load-user-init-file to reset mode-line-format." "Advice for startup--load-user-init-file to reset mode-line-format."
(unwind-protect (unwind-protect
;; Start up as normal ;; Start up as normal
(apply fn args) (apply fn args)
;; If we don't undo inhibit-{message, redisplay} and there's an ;; If we don't undo inhibit-{message, redisplay} and there's an
;; error, we'll see nothing but a blank Emacs frame. ;; error, we'll see nothing but a blank Emacs frame.
(setq-default inhibit-message nil) (when minimal-emacs-inhibit-message-during-startup
(setq-default inhibit-message nil))
(when minimal-emacs-inhibit-redisplay-during-startup
(setq-default inhibit-redisplay nil))
;; Restore the mode-line
(when minimal-emacs-disable-mode-line-during-startup
(unless (default-toplevel-value 'mode-line-format) (unless (default-toplevel-value 'mode-line-format)
(setq-default mode-line-format (setq-default mode-line-format (get 'mode-line-format
(get 'mode-line-format 'initial-value))))) 'initial-value))))))
(advice-add 'startup--load-user-init-file :around (advice-add 'startup--load-user-init-file :around
#'minimal-emacs--startup-load-user-init-file))) #'minimal-emacs--startup-load-user-init-file))
;; Without this, Emacs will try to resize itself to a specific column size ;; Without this, Emacs will try to resize itself to a specific column size
(setq frame-inhibit-implied-resize t) (setq frame-inhibit-implied-resize t)