TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Setting Emacs theme based on ambient light

170 pointsby mbilabout 7 years ago

14 comments

auxymabout 7 years ago
I&#x27;ve had this in my vimrc for a little while:<p><pre><code> let hr = (strftime(&#x27;%H&#x27;)) if hr &gt;= 17 set background=dark elseif hr &gt;= 7 set background=light elseif hr &gt;= 0 set background=dark endif </code></pre> Using a light sensor would be cool, but I actually work from a desktop PC most of the time, so no sensor. I guess the next best thing would be something like f.lux does: query some web service for the sunset time at your current location.
评论 #16805809 未加载
评论 #16809820 未加载
neicabout 7 years ago
There is also circadian.el to change themes based on sunset and sunrise.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;guidoschmidt&#x2F;circadian.el" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;guidoschmidt&#x2F;circadian.el</a>
kfoleyabout 7 years ago
I really like this idea, it&#x27;s something I&#x27;ve been wanting to try out for a while now.<p>I&#x27;m curious if using `run-with-timer` causes any performance issues in emacs. If so one option is to watch the value outside of emacs and then change the theme using `emacsclient -d &quot;(load-theme &#x27;my-dark-theme t)&quot;` from the script.
评论 #16808016 未加载
temp0198209812about 7 years ago
You can leverage the existing sunrise-sunset function to determine if it is day on night and change your theme accordingly.<p>(defun daytime? () (sunrise-sunset) (let ((range (mapcar &#x27;car (butlast (solar-sunrise-sunset (calendar-current-date)))))) (let ((sunrise (car range)) (sunset (cadr range)) (now (string-to-number (format-time-string &quot;%H&quot;)))) (&lt; sunrise now sunset))))<p>(if (daytime?) (light) (dark))
Scarbuttabout 7 years ago
is the background color really the problem? I though screen brightness was a more issue, for example: continue using your light theme but lower down the brightness, most of your websites are going to be white backgrounds, switch between dark and light background frequently strains more the eyes, looking for the link where I read this.
评论 #16808855 未加载
评论 #16806671 未加载
评论 #16808403 未加载
评论 #16811896 未加载
avcdsuiaabout 7 years ago
That&#x27;s why we need OLED displays to save our eyes. With OLED&#x27;s pixels actually produce their own light and dark pixels are just not glowing pixels, pure dark background still provide maximum contrast on sunny days.
评论 #16811566 未加载
todda7about 7 years ago
How to do it on linux? there&#x27;s a package iio-sensor-proxy but who knows how to read out the ambient light from terminal.
评论 #16808767 未加载
mattdemonabout 7 years ago
I sometimes do this manually:<p>M-x set-background-color snow2, snow3, or snow4<p>or wheat2, wheat3, wheat4. or MistyRose1, MistyRose2, MistyRose3.
atherielabout 7 years ago
This is really neat, but I&#x27;m wondering if you are better off triggering the change by sending SIGUSR1 to the Emacs process [0]. This would remove the need to run the function in a timer every 1s.<p>[0]:<a href="https:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;emacs&#x2F;manual&#x2F;html_node&#x2F;elisp&#x2F;Misc-Events.html" rel="nofollow">https:&#x2F;&#x2F;www.gnu.org&#x2F;software&#x2F;emacs&#x2F;manual&#x2F;html_node&#x2F;elisp&#x2F;Mi...</a>
ddavisabout 7 years ago
Thanks for sharing, this is really cool. I often struggle with my Emacs theme switching between light and dark traveling in and out of my windowless office which is filled with intense unnatural night. I once tried to write some Elisp for determining my theme based on the network I was connected to, didn’t work out. I’ll definitely try using this!
mixmastamykabout 7 years ago
Neat. I&#x27;ve done that on the occasional web site, although matched to time of sunrise&#x2F;sunset. I imagine reading from a light sensor is more accurate, but it isn&#x27;t available everywhere yet:<p><a href="https:&#x2F;&#x2F;caniuse.com&#x2F;#search=ambient" rel="nofollow">https:&#x2F;&#x2F;caniuse.com&#x2F;#search=ambient</a>
评论 #16808389 未加载
lprdabout 7 years ago
I&#x27;m not an Emacs user, but this is really cool. Are there any equivalents for vim? Typically, I just set my theme for my shell and vim through base16.
newusertodayabout 7 years ago
Off-topic, is there a way to control chrome&#x2F;firefox through emacs or elisp? something similar to <a href="https:&#x2F;&#x2F;github.com&#x2F;ChromeDevTools&#x2F;awesome-chrome-devtools#chrome-devtools-protocol" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ChromeDevTools&#x2F;awesome-chrome-devtools#ch...</a>.
saagarjhaabout 7 years ago
I have something similar, except it&#x27;s based on sunrise&#x2F;sunset. It hooks into my Mac&#x27;s Night Shift timer to also enable dark mode and a darker color scheme in all my text editors when it&#x27;s getting close to sunset, and undo it when the sun rises.