Skip to content

oliverepper/pif

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 

Repository files navigation

Prevent Initial Flash of Light

pif.el prevents the initial “Flash of Light” during Emacs startup.

In addition to reducing the “Flash of Light”, it ensures that the initial frame appears in the correct size and position – just as it was when Emacs was closed. Furthermore, it hides GUI elements such as the modeline, fringes, and the cursor during startup for a distraction-free initialization.

Demo

Before and after comparison: PIF.el Demonstration.

Features

  • Prevents the initial “Flash of Light” during Emacs startup.
  • Ensures the initial frame loads with the correct dimensions and position.
  • Hides GUI elements (modeline, fringes, and cursors) during startup to minimize visual distractions.
  • Restores values after the initial startup to prevent surprises when loading custom themes.
  • Supports light and dark-mode.

Setup

The public interface of pif.el consists of four functions:

pif-early

This hides some UI-elements (cursor, tool-bar, scroll-bar, and modeline) during early startup. Call it early in your early-init.el.

(add-to-list 'load-path (expand-file-name (locate-user-emacs-file "local/pif")))
(require 'pif)

(pif-early)

pif APPEARANCE

This function sets the foreground and background color of the default and the fringe face to prevent the “Flash of Light”. I use pif.el on a Mac and my Emacs distribution features the hook ns-system-appearance-change-functions which gets called early enough during startup so that my next line in early-init.el is:

(add-hook 'ns-system-appearance-change-functions #'pif)

You can, of course, just call (pif 'dark), if you always work in dark mode, or come up with your own sophisticated mechanism.

pif-reset

This resets the colors back to the values they had before pif was called. I call this first at the top of my init.el and I remove ~pif~ from the ~ns-appearance-change-functions~:

(when (featurep 'pif)
  (pif-reset)
  (remove-hook 'ns-system-appearance-change-functions #'pif))

CAUTION: The initial value for the property background of the default face is unspecified-bg. Since this value cannot be set from elisp pif-reset resets it to unspecified. The same is true for foreground and the value unspecified-fg.

pif-update

This is the function that saves the current background color, as well as the position and size of the initial frame so that these can be used during startup. You can call this function whenever things change, but a simple and robust place is the kill-emacs hook.

(add-hook 'kill-emacs-hook (lambda ()
                             (pif-update ns-system-appearance)))

Summary

  • Call pif-early and pif APPEARANCE from your early-init.el file.
  • Call pif-reset early in your init.el file. (Also remove any hook that calls pif APPEARANCE.)
  • Call pif-update from the kill-emacs hook.

Example early-init.el

(add-to-list 'load-path (expand-file-name (locate-user-emacs-file "local/pif")))
(require 'pif)

(pif-early)
(add-hook 'ns-system-appearance-change-functions #'pif)

Example init.el

(when (featurep 'pif)
  (pif-reset)
  (remove-hook 'ns-system-appearance-change-functions #'pif)
  (add-hook 'kill-emacs-hook (lambda ()
                               (pif-update ns-system-appearance))))

Contributing

I am still fairly new to Emacs and this is my first shot at creating a package. If you find a bug or have any suggestions, feel free to open an issuse or submit a pull request.

Acknowledgments

  • Christian Tietze: Thank you for darwing my attention to Emacs!
  • Protesilaos Stavrou (Prot): Thank you for beeing a great resource for learning Emacs! Your detailed tutorials and the packages you create are very helpful. I got the idea for this package from your Emacs configuration.

About

Prevent Initial Flash of Light

Resources

License

Stars

Watchers

Forks

Packages

No packages published