Emacs: rainbow-identifiers #

After reading Evan Brook's post about using text editor colors for identifiers instead of keywords, I decided to try the Emacs rainbow-identifiers and color-identifiers-mode. I find rainbow-identifiers easier to configure (it's language agnostic), and the color choices are stable while editing. I find color-identifiers to generate better output when reading code. It highlights only the local identifiers instead of all words, so the colors are more meaningful. Try both and see which works best for you.

Before, using colors for keywords:

var edges = this.graph.edges_from(this.curr);
for (var i = 0; i < edges.length; i++) {
    var next = edges[i];
    var edge_weight = this.graph.edge_weight(this.curr, next);
    if (edge_weight != Infinity) {
        this.neighbors.push(next);
        mark_changed(next);
        if (!this.visited[next]) {
            this.g[next] = this.g[this.curr] + edge_weight;
            this.open.push(next);
            this.parent[next] = this.curr;
            this.visited[next] = true;
        }
    }
}

After, using rainbow-colors mode:

var edges = this.graph.edges_from(this.curr);
for (var i = 0; i < edges.length; i++) {
    var next = edges[i];
    var edge_weight = this.graph.edge_weight(this.curr, next);
    if (edge_weight != Infinity) {
        this.neighbors.push(next);
        mark_changed(next);
        if (!this.visited[next]) {
            this.g[next] = this.g[this.curr] + edge_weight;
            this.open.push(next);
            this.parent[next] = this.curr;
            this.visited[next] = true;
        }
    }
}

After, using color-identifiers mode (notice how it uses colors for fewer identifiers, so they stand out better):

var edges = this.graph.edges_from(this.curr);
for (var i = 0; i < edges.length; i++) {
    var next = edges[i];
    var edge_weight = this.graph.edge_weight(this.curr, next);
    if (edge_weight != Infinity) {
        this.neighbors.push(next);
        mark_changed(next);
        if (!this.visited[next]) {
            this.g[next] = this.g[this.curr] + edge_weight;
            this.open.push(next);
            this.parent[next] = this.curr;
            this.visited[next] = true;
        }
    }
}

Here's how — I first turned off font-lock colors:

(set-face-attribute 'font-lock-comment-face nil :foreground nil :slant 'italic)
(set-face-attribute 'font-lock-comment-delimiter-face nil :slant 'italic)
(set-face-attribute 'font-lock-constant-face nil :foreground nil :underline t)
(set-face-attribute 'font-lock-type-face nil :foreground nil)
(set-face-attribute 'font-lock-function-name-face nil :foreground nil :weight 'bold)
(set-face-attribute 'font-lock-variable-name-face nil :foreground nil)
(set-face-attribute 'font-lock-keyword-face nil :foreground nil :slant 'italic)
(set-face-attribute 'font-lock-string-face nil :background "#e0e0e0")
(set-face-attribute 'font-lock-builtin-face nil :foreground nil :slant 'italic)

Second, I want colors chosen from L*a*b* color space because it makes the perceived brightness consistent across colors. It turns out color-identifiers mode already uses L*a*b* colors. In rainbow-identifiers mode, I configured it like this:

(loop for i from 1 to 15 do
      (let* ((lightness 45)
             (saturation 40)
             (angle (* 2 pi (/ i 15.0)))
             (a (* saturation (cos angle)))
             (b (* saturation (sin angle))))
        (set-face-attribute 
             (intern (format "rainbow-identifiers-identifier-%s" i))
             nil
             :foreground (apply 'color-rgb-to-hex
                             (color-lab-to-srgb lightness a b)))))

This generates these colors:

rainbow-identifiers-identifier-1
rainbow-identifiers-identifier-2
rainbow-identifiers-identifier-3
rainbow-identifiers-identifier-4
rainbow-identifiers-identifier-5
rainbow-identifiers-identifier-6
rainbow-identifiers-identifier-7
rainbow-identifiers-identifier-8
rainbow-identifiers-identifier-9
rainbow-identifiers-identifier-10
rainbow-identifiers-identifier-11
rainbow-identifiers-identifier-12
rainbow-identifiers-identifier-13
rainbow-identifiers-identifier-14
rainbow-identifiers-identifier-15

Pretty! You can change the color selection by changing the lightness and saturation constants. I'll try this for a while. Update: [2014-05-15] rainbow-identifiers 0.1.3 now has an option for using L*a*b* colors without needing the above code. Use (setq rainbow-identifiers-choose-face-function 'rainbow-identifiers-cie-l*a*b*-choose-face)

Edit: [2014-05-18] The original post was about rainbow-identifiers mode; I updated it to also show color-identifiers mode.

Labels:

Building Mac OS X Emacs 24 #

Update: [2014-10-23] After a long wait, Emacs 24.4 is finally out. The binaries for the Yamamoto Mitsuharu version are available from railwaycat. The blog post is updated for Emacs 25.1 release candidate. I have another blog post for Emacs 26 pretest.

I'm a long time Emacs user. When using a Mac, I've been using the builds from emacsformacosx.com. After reading about the new features in 24.4, I tried the Emacs nightly builds, and was mostly happy with them, but I somehow messed up my Emacs package configuration in a way that I can't go back to Emacs 23.3. No big deal, right? So I waited for the 24.3.90 pretest to go back to a somewhat "stable" version, and that just came out last week.

The problem is that the emacs 24.3.90 pretest from emacsformacosx.com is triggering a runaway distnoted process on my system, and is also running rather slowly. There are some patches floating around there, but I'd have to build from source. I've also been curious about the Yamamoto Mitsuharu version of Emacs; see this list of features. If I'm going to build from source, I might as well try his version, right?

Labels: ,

Bluetooth tooth #

People sometimes get tooth implants to replace missing or decayed teeth. Currently they're milled or 3d printed. But I think we could do much more. Why not put bluetooth into your tooth? We'd get:

  • Speaker so that you could listen to tunes streamed from your phone.
  • Microphone attached to the bone so that you could make phone calls without nearby people overhearing what you say.
  • Sensors to measure and report the status of your mouth. Real time graphs of saliva, food, and dental bacteria can be sent to your phone, like a Fitbit for your mouth.

It'll finally turn the "tooth fillings pick up radio signals" myth into reality. Would you get one? I would!

Labels:

Scented sweat #

Many or perhaps all of the smells produced by your body are produced by the bacterial ecosystems living on and in you. Some of these smells are things we can detect; others we're unaware of. Certain strains of skin bacteria attract mosquitos. By altering the ecosystem on our skin, we can repel mosquitos. Cool!

With genetic engineering, we can do even more. We can replace the bacteria that turn sweat into unpleasant smells with bacteria that turn sweat into floral scents! No more deodorant!

Labels: ,

Future tattoos #

Today's tattoos are boring. Future tech will bring:

  1. Bioluminescent tattoos: using bioluminescent chemicals, your tattoos will glow or pulse, either all the time, or synchronized with a clock, or triggered by movement or light or sound. Imagine going to a dance club with this.
  2. E-ink tattoos: with e-ink particles embedded in your skin, you'll be able to change the pattern by applying an external array of electric fields. You'll place the “printer” on your arm, apply a new pattern, and then it'll hold that pattern until you want to change it.
  3. Biosensor tattoos: with e-ink particles attached to a layer of biosensor molecules, you'll be able to find out what's going on in your blood. You'll set up blocks that are sensitive to 50, 100, 150, 200 mg/dL of glucose, and then by seeing how many bars are “lit up”, you'll have a rough estimate of your blood sugar. You could do this for everything in your bloodstream.

Cool? or creepy?

Labels: ,