Re: [GNU ELPA] New package: caffeinate-mode

Stéphane Marks <[email protected]>
Newsgroups gmane.emacs.devel
Message-ID <CAN+1Hbpn4mQk4WpGb2nEiqsCPNPrye+Q87dcj+0kKfkueVyY7g@mail.gmail.com>
On Sun, Jul 19, 2026 at 11:34 AM Philip Kaludercic <[email protected]>
wrote:

> Lucas Christian <[email protected]> writes:
>
> > Hi all,
> >
> > Long-time Emacs user, first-time contributing a package.
> >
> > One of the more practical additions I am excited about in Emacs 31 is
> > the system-sleep package, which provides a native hook into the
> > operating system's power management APIs.  Long-term, I suspect the
> > potential of system-sleep will come from it being integrated into many
> > Emacs workflows so that the user never has to think about preventing
> > their system from going to sleep while Emacs executes long-running
> > tasks.  Until then, I wrote this package to get system-sleep in front of
> > many users by offering a simple proposition: it can replace the GUI or
> > external command line tool they are likely already using.
> >
> > caffeinate-mode solves the simple and generic case of "I started some
> > long-running task (that doesn't integrate directly with the OS power
> > management APIs), I want to manually tell the system not to sleep so it
> > can complete without interruption".  Users may already be using various
> > utilities for this such as "Caffeine" (GNOME extension or macOS app by
> > the same name), systemd-inhibit (Linux CLI tool), or caffeinate (macOS
> > equivalent).
>
> (Android also has an option by this name.  I didn't know what it does for
> a long time, but apparently this term is becoming more standard.)
>
> >               On previous versions of Emacs, I frequently found myself
> > launching "caffeinate" from M-x async-shell-command for these use cases.
> >
> > Package description:
> >
> >   This package provides two global minor modes that can be toggled on
> >   any time it would be inopportune for the system to sleep:
> >
> >   - caffeinate-mode blocks system idle sleep but allows the display to
> >     sleep.
> >
> >   - display-caffeinate-mode blocks system idle sleep and also keeps the
> >     display active.
>
> >   The modes are mutually exclusive: enabling one automatically disables
> >   the other.  Disabling either mode releases the active power assertion,
> >   allowing the system to resume its normal sleep behavior.
>
> I don't get why you need two separate options for this, can you not have
> one major mode with two values (recall that each minor mode is also a
> user option)?  You can use a prefix argument in an interactive setting
> to force the other mode, depending on which of the two you consider to
> be more interesting.
>

I agree it is a bit wonky to have two minor modes when one would suffice.
I would not make the main menu item mandatory.  I have some stylistic
comments to the code at a general level but if it works for you, it can be
improved over time.

As the author of system-sleep, I specifically didn't add such a mode
because the intention was never to replace O/S utility calls that affect
the entire system but to allow long-running Emacs operations to declare
(via hooks or other in-built policies) they want the system to remain
awake.  e.g., when running M-x compile, one could in
a compilation-mode-hook declare a stay-awake policy.  Separately, an
optional mode-line system sleep indicator could be useful but that seems
separate to your package and would provide a touch more utility across
system-sleep estate that doesn't leverage caffeinate.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.