early morning musing (in Lisp)
Oct. 22nd, 2004 03:58 am![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
y’know, it’s really too bad I can’t set Windows up with something like this:
(defun my-colors-light (&optional frame)
"Set colors suitable for working in light environment,
i.e. in daylight or under bright electric lamps."
(interactive)
(if frame
(select-frame frame)
(setq frame (selected-frame)))
;; Color with minimal eye fatigue in light environments
;; is "AntiqueWhite3" (RGB: 205 182 176),
(set-background-color "AntiqueWhite3")
(set-foreground-color "black")
(set-cursor-color "DarkSlateGrey")
(when (facep 'region)
(set-face-background 'region "DarkGrey" frame))
(when (facep 'fringe)
(set-face-background 'fringe (face-background 'default) frame)
(set-face-foreground 'fringe (face-foreground 'default) frame)))
(define-key global-map [f6 ?c ?s] 'my-colors-light)
(defun my-colors-dark (&optional frame)
"Set colors suitable for working in the darkness without electricity."
(interactive)
(if frame
(select-frame frame)
(setq frame (selected-frame)))
(set-background-color "black")
(set-foreground-color "DarkGrey")
(set-cursor-color "DarkSlateGrey")
(when (facep 'region)
(set-face-background 'region "DimGrey" frame))
(when (facep 'fringe)
(set-face-background 'fringe (face-background 'default) frame)
(set-face-foreground 'fringe (face-foreground 'default) frame)))
(define-key global-map [f6 ?c ?d] 'my-colors-dark)
;; Automatically switch to dark background after sunset
;; and to light background after sunrise.
;; (Not that 'calendar-latitude' and 'calendar-longitude'
;; should be set before calling the 'solar-sunrise-sunset')
(defun my-colors-set (&optional frame)
(interactive)
(require 'solar)
(if (and calendar-latitude calendar-longitude calendar-time-zone)
(let* ((l (solar-sunrise-sunset (calendar-current-date)))
(sunrise-string (apply 'solar-time-string (car l)))
(sunset-string (apply 'solar-time-string (car (cdr l))))
(current-time-string (format-time-string "%H:%M")))
(if (or (string-lessp current-time-string sunrise-string)
(string-lessp sunset-string current-time-string))
(my-colors-dark frame))
(if (and (boundp 'my-sunset-timer) (timerp my-sunset-timer))
(cancel-timer my-sunset-timer))
(if (and (boundp 'my-sunrise-timer) (timerp my-sunrise-timer))
(cancel-timer my-sunrise-timer))
(setq my-sunset-timer (run-at-time sunset-string (* 60 60 24) 'my-colors-dark))
(setq my-sunrise-timer (run-at-time sunrise-string (* 60 60 24) 'my-colors-light)))))
(my-colors-set)
(add-to-list 'after-make-frame-functions 'my-colors-set)