Be Nice to Your Eyes in Emacs

If you’re one of the many right-minded geeks who uses Emacs, you have an advantage over those who use less-flexible text editors. Anyone staring at code all day long will soon suffer from tired eyes. If you use Emacs, though, you can use a macro that I wrote that may help alleviate the problem.

Disclaimer: If you’re having problems with your eyes you should always see your optometrist first. For example, if you see double at the end of a long day of staring at a computer screen you may benefit from doctor-prescribed eye exercises or glasses. The script presented here is not going to help you with any serious medical problem, so don’t blame me if it doesn’t fix your eyes, balance your checkbook, or bring world peace. Caveat Emptor.

The basic idea is to automatically cycle the colors that Emacs uses every few minutes so that your eyes don’t get tired from seeing the same colors all day long. You might think that it would be pretty distracting for your editor to suddenly change colors every few minutes, but I found that after using the script for a short while I no longer notice when the colors change. I do notice, however, that my eyes seem less tired at the end of a long day of coding.

I’ve provided some initial color schemes that work well for me, but you can easily change them or add more. I’ve selected two standard editor color schemes and a variation (black on white, blue on white, and purple on off-white) plus two other color schemes informed by business forms research.

A friend in the business forms industry once passed on a bit of insider knowledge to me about forms–apparently dark brown text on a light green background is easy on the eyes when reading lots of data, and dark blue text on a light yellow background results in fewer clerical errors when filling out forms. As a result I’ve included these two color schemes in my color-cycling macro. Periodically your eyes will get a five minute rest, and periodically you’ll be especially good at spotting bugs.

To install the macro, just download cycle-colors.el and either paste the file contents into your .emacs file or add the following line to your .emacs file:

(load "cycle-colors")

The macro installs two global key mappings: Ctrl-x+c (lower-case “c”) switches to the next color scheme, and Ctrl-x+C (upper-case “C”) toggles the color cycling on and off. You’ll want to modify those mappings if you already use those keys for something else.

One thought on “Be Nice to Your Eyes in Emacs

  1. vedang

    Thanks, this is a really fun bit of code. You might be interested in checking out my default colorscheme:

    (set-foreground-color “lightgreen”)
    (set-background-color “black”)
    (set-cursor-color “white”)

Leave a Reply