The magic-mode-alist

Most Emacs users know how to associate a file type with a major mode by using the auto-mode-alist variable to associate a file extension with a major mode. I recently learned of another way thanks to Xah Lee who posted a note on associating files with a major mode.

It turns out that you can use the beginning of a file to associate it with a major mode in much the same way that the Unix file command determines the type of file from the first few bytes of the file. To do this you add a cons of a regular expression matching the beginning of the file and the major mode to invoke to the magic-mode-alist variable. Lee gives this example to invoke nxml-mode for html files:

(add-to-list 'magic-mode-alist '("<!DOCTYPE html .+DTD XHTML .+>" . nxml-mode))

Emacs checks the magic-mode-alist variable before checking auto-mode-alist so the beginning of file check takes precedence. You can also specify a function instead of the regex to deal with situations too complex for a regular expression.

Lee’s post has a nice summary of all the ways Emacs can associate a major mode with a file so you should give it a look.

Posted in General | Tagged | Leave a comment

Readable S-Expressions

Why do people keep doing this? They should stop. Now. Really.

There is nothing wrong with parentheses. Lispers like them and deal with them without difficulty.

There is nothing wrong with Lisp syntax. Lispers like it and deal with it without difficulty.

There is nothing awkward about S-expressions. They are not hard to read and, really, those who find the prefix notation confusing or fail to understand its advantages should find another way to earn a living.

If you think Lisp should to be like Python, just use Python. The Lispers and Pythonistas will both be thank you.

If you’re going to quote Paul Graham, don’t use his words to make a point that he certainly wouldn’t agree with.

Afterward:

Reading this over, it may seem a little harsh. Certainly Wheeler is entitled to work on any project he likes and to scratch anything that itches but I don’t see the point of this project. It tries—unsuccessfully, I think—to fix things that Lispers don’t see as broken and produces a syntax that starts with the clean and elegant Python and makes it ugly. Actually, I think Pythonistas should be more offended than Lispers at the result.

To paraphrase DMR, if you want Python, you know where to find it.

Posted in Programming | Tagged | 1 Comment

Emacs

It’s everywhere!

Posted in General | Tagged | Leave a comment

The Emacs Manual in Info

This is definitely a note to myself. Doubtless everyone knows this but for some reason I can never seem to remember it so I am recording it in a post. If you’re an Emacs user and your initials are not RMS, you probably have occasion to consult the Emacs manual. When I find myself in that position I most often just bring it up in my browser. That’s easy because I have it book marked but it’s also a little silly since Emacs has the manual built in.

Of course you can always do 【Ctrl+h i】 and then pick the Emacs manual entry but there’s a better way. You can bring up the manual directly with 【Ctrl+h r】. That’s almost no savings in labor but somehow it seems much quicker and easier. At least it would be if I could remember it.

Posted in General | Tagged | 3 Comments

Lena

I ran across this astounding story of Singapore researchers at Singpore’s Agency for Science, Technology and Research generating a digital image with 100,000 DPI resolution. This is close to the theoretical maximum resolution and is therefore a significant achievement.

What impressed me, though, is the backstory of the image itself. The picture is of Lena Söderberg, a Swedish model who was a 1972 Playboy centerfold. This picture is a standard digital image that researchers use for experimenting with new digital algorithms and has been used for 40 years. The picture was originally chosen when researchers needed an image to scan for a paper. They looked through the standard stock images but everything seemed boring. At that point, somebody walked in with the current issue of Playboy and the researchers tore off the top third of the image so that it would fit on the drum of the scanner and an icon was born.

In 1997, Lena attended the 50th Anniversary of the Society for Imaging Science and Technology conference and met many of the scientists who have been using her picture for 4 decades. She’s now happily married with 3 children and works for the government. It wasn’t until 1988 that she first learned what had happened to her picture. She’s said to have been pleasantly amused. At the conference she commented to a Wired reporter, “They must be so tired of me … looking at the same picture for all these years!”

None of this is important, of course, but it is a charming story that gives us a glimpse into the real person behind a standard and well known test image. You can read more about Lena’s story by following the above links.

Posted in General | Leave a comment

Scientific American on Piracy

David Pogue over at Scientific American has an interesting article that makes a point that most Irreal readers are familiar with: Hollywood encourages piracy by not making movies available legally. Pogue points out that many popular movies are not available to rent online and that none of the 10 most pirated movies can be viewed online legally. The result of this, of course, is that users—who are not at all inclined to be denied—simply download the movies illegally netting Hollywood no income from the viewing.

It doesn’t have to be this way. The music industry has already figured this out. Some people will pirate regardless of availability but the vast majority of people simply want to see the movie and would happily pay for it if it was available. Of course, this is well known and was neatly captured by the now famous Oatmeal cartoon. The industry mumbles about existing agreements and protocols as if these things were out of its control. Of course, they aren’t—it’s Hollywood for goodness sakes.

As I said, none of this is news to the people around here but it’s significant that we’re now reading these opinions in organs such The New York Times and Scientific American. It’s one thing to have nerds pointing out the obvious but quite another when the establishment media starts mentioning the same inconvenient truths.

Posted in General | Tagged | Leave a comment

Jon Bentley on Quicksort

One of my heroes in Jon Bentley. If you don’t know who he is, this post is for you. If you do know who he is, this post is also for you. Bentley is one of the original Bell Labs researchers from the Lab’s golden age. Many of you will know him through his Communications of the ACM Programming Pearls columns and the three books that recapitulated those columns.

Bentley is a guy who is vitally concerned with algorithms and how to optimize them. If you haven’t read Programming Pearls and the two sequels, you’re really missing out. I can’t emphasize enough how influential these books were on my development as a programmer. If you haven’t read them, you need to do so immediately. Really.

Bentley recently gave a talk at Google in which he attempts to answer the question “What is the most beautiful code you’ve ever written?” Being Bentley, the answer is not simply X but rather a careful and extensive exposition of his reimplementation of the quicksort algorithm. Nothing I could say can begin to give justice to this talk. It is, really, a distillation of what makes Bentley Bentley. You really MUST watch this video. Believe me, you won’t be sorry. This is a great talk and you WILL learn a lot.

Posted in Programming | Leave a comment

A Malware Debugging Tool From Google

After Irreal’s recent malware incident I’ve been keeping an eye out for ways to avoid any further exploits and for taking remedial action in case Irreal is reinfected. The particular piece of malware that attacked Irreal was only interested in Windows machines running either Internet Explorer or Firefox and therefore only injected code for those systems.

One of the problems with that is that it’s hard for those of us running other OSs or browsers to test for and find infected sites. As it turns out, Google offers a useful tool that does just that. The fetch-as-google tool allows you to see the site as the Google crawler does. This is a really handy debugging tool and one that everyone maintaining an Internet site should be familiar with.

I learned about it from this post on Matt Cutt’s blog. The tool itself is available from the Google Webmaster Tools, which has many useful tools for webmasters. Again, if you’re responsible for a Web site be sure to take a look at Cutt’s post and checkout Google Webmaster Tools.

Posted in General | Tagged , | Leave a comment

A Small But Nice Change to the Org-Mode Build Process

As regular readers know, I’m a great admirer of Org-mode; I use it everyday to, among other things, write these blog posts, maintain my todo list, manage projects, and keep several other files up to date.

I generally track the development Git repository but I haven’t updated since 7.8.03. Today I upgraded to 7.8.11 and noticed a small but very nice change. The procedure after doing a Git pull is to run make in the Org-mode directory and then do a 【Meta+xorg-reload to load the new software. The problem is that Org’s Makefile doesn’t work with OS X because the Emacs executable is stored in a Mac specific place.

I wrote a small shell script to modify Makefile to account for this but then the next pull would fail because there was a modified Makefile in the directory. I tried to remember to delete the modified file before the pull but, of course, I seldom did. It wasn’t a big thing, just a minor annoyance.

Today when I did the pull I noticed the Makefile had changed. Now, you’re not supposed to edit the make file itself but just put your changes in local.mk. Since local.mk is strictly local it doesn’t get overridden by the pull and there’s no need to fix things up every time you update. As I said, it’s a small change but it eliminates an annoyance and makes updating just a bit more frictionless. Many thanks to the Org maintainers for making my life easier.

Posted in General | Tagged | Leave a comment

Imagine That

For years the music industry has been whining about the digital apocalypse in general and streaming in particular. They were steadfast in their refusal to consider embracing new business models and held firm to the model that had always worked so well in the past.

Now All Things D is reporting that streaming accounted for 25% of Warner Music Group’s revenue in the last quarter. Significantly, the increase in streaming revenue did not come at the expense of traditional digital sales such as iTunes. Also significant is the fact that the increase in digital sales is greater than the decrease in the sale of physical media.

As many of us have said for years, the industry would have been much better off to devise and deploy new business models rather than suing their customers and third party enterprises that were trying to deliver music in new and efficient ways. None of this means that the music industry is changing its ways, of course, only that they’ve lost one more excuse for their shortsightedness.

Posted in General | Tagged | Leave a comment