This blog has my random thoughts; game-related posts go here.

A few weeks ago I posted how to make Mac OS Spotlight index source code. Mac OS is already indexing my C, C++, ObjC, Java, Fortran, Shell, Python, Perl, Ruby, Pascal, Ada, Javascript, and HTML files, but it doesn't get the other languages and text files I use. Here's the followup post.

Problem to solve: I want to search the contents of *.css and other text files with Spotlight.

In my previous blog post, I went into the Spotlight configuration file and told it to index certain file types like dyn.ah62d4rv4ge80e8drru, which I had determined was *.css. This wasn't satisfying. Instead of telling Spotlight, I wanted a solution at the Mac OS level.

Labels: ,

A typical way to use Emacs is to open lots of files as buffers. In the default Emacs setup, the command to switch to a file depends on whether the file is open:

  File Non-file
Opened C-x b
Not opened C-x f N/A

I don't want to have to remember whether a file is open. Instead, I want the command to depend on whether I'm switching to a file or a non-file. I also want to find files without having to switch folders first, because I work on lots of small projects in different folders. I use these bindings:

  File Non-file
Opened Cmd T C-x b
Not opened N/A

In a previous post, I described my previous attempt, using helm-for-files to open files from many different directories, using locate (mdfind on Mac). As part of that, I improved my Mac OS mdfind setup to include all my text files. I was hoping that I could make mdfind fast and precise enough that I'd use it all the time. Unfortunately I couldn't get the queries to run faster than 300 milliseconds, and it didn't feel fast enough to run on every keystroke. There are other emacs packages to do this but I ended up with my own custom setup to make this:

Labels:

Mac OS X has a real time file indexing system called Spotlight. By itself, it's not terribly useful for me. What makes it useful is that it's accessible from the command line. I can search filenames:

locate mapgen2.as
mdfind -name mapgen2.as

The locate command relies on a database that's rebuilt nightly; mdfind is updated in real time. Spotlight also indexes the contents, which gives me something similar to recursive fgrep:

fgrep -R word *
mdfind -onlyin . word

It won't search for arbitrary regexps but for quickly narrowing down files to find certain words, it's useful.

Labels: ,

I use Safari's Reading List to transfer pages from my phone to my computer. But I don't really want to read these in Safari on my desktop. I'd rather read them in Firefox, maybe through Pinboard, which has an API to write items and mark them as "to read". This blog post documents what I learned.

I searched the web for some resources, and learned that the reading list, as well as other Safari bookmarks, are stored in ~/Library/Safari/Bookmarks.plist. I can use plutil and PlistBuddy to read and edit that file.

Labels: ,

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: