I've had this in my vimrc for a little while:<p><pre><code> let hr = (strftime('%H'))
if hr >= 17
set background=dark
elseif hr >= 7
set background=light
elseif hr >= 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.
There is also circadian.el to change themes based on sunset and sunrise.<p><a href="https://github.com/guidoschmidt/circadian.el" rel="nofollow">https://github.com/guidoschmidt/circadian.el</a>
I really like this idea, it's something I've been wanting to try out for a while now.<p>I'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 "(load-theme 'my-dark-theme t)"` from the script.
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 'car (butlast (solar-sunrise-sunset (calendar-current-date))))))
(let ((sunrise (car range))
(sunset (cadr range))
(now (string-to-number (format-time-string "%H"))))
(< sunrise now sunset))))<p>(if (daytime?) (light) (dark))
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.
That's why we need OLED displays to save our eyes. With OLED'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.
This is really neat, but I'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://www.gnu.org/software/emacs/manual/html_node/elisp/Misc-Events.html" rel="nofollow">https://www.gnu.org/software/emacs/manual/html_node/elisp/Mi...</a>
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!
Neat. I've done that on the occasional web site, although matched to time of sunrise/sunset. I imagine reading from a light sensor is more accurate, but it isn't available everywhere yet:<p><a href="https://caniuse.com/#search=ambient" rel="nofollow">https://caniuse.com/#search=ambient</a>
I'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.
Off-topic, is there a way to control chrome/firefox through emacs or elisp? something similar to <a href="https://github.com/ChromeDevTools/awesome-chrome-devtools#chrome-devtools-protocol" rel="nofollow">https://github.com/ChromeDevTools/awesome-chrome-devtools#ch...</a>.
I have something similar, except it's based on sunrise/sunset. It hooks into my Mac's Night Shift timer to also enable dark mode and a darker color scheme in all my text editors when it's getting close to sunset, and undo it when the sun rises.