emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Introduce .early-init.desktop (inspired by early-init.el) -- needed


From: David Hedlund
Subject: Re: Introduce .early-init.desktop (inspired by early-init.el) -- needed to avoid visually distracting settings
Date: Mon, 26 May 2025 13:16:26 +0200
User-agent: Mozilla Thunderbird

I would like to kindly invite Emacs developers to review and chime in with their thoughts on this feature request. I’ve spent about two working weeks resolving various background issues, and it took considerable effort for the test case to come into realization. I believe this feature request could be considered a core usability improvement for Emacs GTK that has not yet been implemented, and it would help make Emacs more approachable for beginners.

On 2025-05-03 08:05, David Hedlund wrote:

Hello Emacs Developers,

The desktop file is used to save settings-such as window state-if they are toggled during your Emacs session. I’d like to propose a new feature for Emacs: support for a .early-init.desktop file, analogous to early-init.el, to improve the user experience when restoring frame/window state on startup.

Current behavior (.emacs.desktop)

  • Add the following lines to your `init.el` file:
(desktop-save-mode 1)
(setq desktop-save t)
  • Launch emacs-gtk.
  • Manually maximize the Emacs window.
  • Close Emacs.
  • The maximized window state `(fullscreen . maximized)` will be saved in your `.emacs.desktop` file.

Proposed behavior (.early-init.desktop)

  • Add the following lines to your `init.el` file:
(desktop-save-mode 1)
(setq desktop-save t)
  • Launch emacs-gtk.
  • Manually maximize the Emacs window.
  • Close Emacs.
  • The maximized window state `(fullscreen . maximized)` will be saved in your `.early-init.desktop` file.

Background

Currently, users can start Emacs maximized via elisp by:

  • Placing (push '(fullscreen . maximized) default-frame-alist) at the top of their early-init.el (see the "early-init.el: How can I start the Emacs window maximized?" section below).

  • Alternatively, enabling desktop-save-mode will save the frame state (including `(fullscreen . maximized)`) in .emacs.desktop. (see steps under the "Proposed behavior (.early-init.desktop)" section above.) However, when restoring from .emacs.desktop, the frame is first created at its default size and then resized, causing a visible and distracting flicker for users who want Emacs to start maximized or fullscreen.

early-init.el: How can I start the Emacs window maximized?

From https://www.gnu.org/software/emacs/manual/html_mono/efaq.html#Start-Emacs-maximized

"Run Emacs with the ‘--maximized’ command-line option or put the following form at the top of your early init file (see Early Init File in The GNU Emacs Manual).

(push '(fullscreen . maximized) default-frame-alist)

Note that while some customizations of default-frame-alist could have undesirable effects when modified in the early init file, it is okay to do it in this particular case. Adding it to the top of your normal init file will also work, but leads to a visible resizing of the window that some find distracting."

.emacs.desktop problem

  • Current desktop restoration causes a visible resize:
    The window appears, then resizes to the saved state, which is visually distracting.

  • Early frame customization is possible in early-init.el but not via the desktop mechanism:
    Users who rely on session restoration cannot benefit from early frame state application.

Suggestion: .early-init.desktop

I propose introducing a .early-init.desktop file, which would be loaded before .emacs.desktop, similar to early-init.el is loaded before init.el. This file would contain frame/window state information (e.g., maximized, fullscreen, geometry) and allow Emacs to apply these settings before the first frame is shown.

Benefits

  • Seamless startup:
    The initial frame appears in the correct state, eliminating distracting resizes.

  • Consistent experience:
    Users who rely on session restoration get the same early customization benefits as those who edit early-init.el.

  • Backward compatibility:
    Existing .emacs.desktop files and workflows remain unchanged for users who don’t opt into the new feature.

Possible Implementation

  • On exit, Emacs could write frame state to .early-init.desktop (or as an option in desktop-save-mode).

  • On startup, Emacs would read .early-init.desktop before creating the first frame, applying the saved state.

  • Only a small subset of settings from .emacs.desktop should be migrated to .early-init.desktop. At present, the only setting I recommend for this is (fullscreen . maximized), as this aligns with our guidance for early window maximization in early-init.el-avoiding the distracting visible resizing that occurs when maximization is applied later in the startup process (see the "early-init.el: How can I start the Emacs window maximized?" section above.)

Discussion Points

  • Should it be integrated with or independent of desktop-save-mode?

  • Perhaps, for consistency with init.el and early-init.el, .emacs.desktop should also be renamed to .init.desktop-if .early-init.desktop gets implemented.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]