The Emacs Regular Expression Builder

Emacs’ regular expressions are notoriously tricky. They aren’t Perl Regular Expression compatible and the escaping rules are not always what you’d expect if you’re used to Unix regular expressions. Most of us, therefore, have experienced wasted time and frustration trying to get a complicated regular expression right. Fortunately, Emacs provides a tool to help ease the way: re-builder.

re-builder provides interactive feedback on your regular expression as you build it. Any matches for a partial or complete regular expression are shown in the current buffer. If you have subexpressions, they are highlighted in a different color so you can see if you’re getting what you expected (non-color displays are handled too). If the regular expression is invalid (at any point) re-builder will tell you and you can query the error with 【Ctrl+c Ctrl+u】 to find out why re-builder is complaining.

When you’re satisfied with the regular expression, you can copy it to the kill ring with 【Ctrl+c Ctrl+w】 and then quit re-builder with 【Ctrl+c Ctrl+q】.

Although re-builder attaches itself to the buffer that is current when you call it, you can change the target buffer with 【Ctrl+c Ctrl+b】 and the desired buffer name.

Summary

Key Sequence Action
Ctrl+c Ctrl+u Show Error
Ctrl+c Ctrl+b Change Target Buffer
Ctrl+c Ctrl+w Copy Regular Expression to Kill Ring
Ctrl+c Ctrl+q Quit re-builder
Posted in General | Tagged | 1 Comment

Happy Programmers’ Day

Today is the 0x100th day of the year: Programmers’ Day. So Happy Programmers’ Day to all my fellow programmers.

Posted in General | Leave a comment

A Lightweight Alternative To Emacs Org Mode

As regular readers know, I am fanatical Org mode user. Almost everything I write in Emacs that isn’t programming code ends up in Org mode. Sometimes, even code does. Still, Org mode is a large system with lots of functionality and that can make it hard to learn.

I recently came across an Emacs package that gives some of the functionality of Org mode and is much simpler to use. Deft is an Emacs mode for dealing with notes. Jason Blevins modeled Deft on Notational Velocity, a Mac note management program. Deft keeps each note in a separate file in the ~/.deft directory (configurable). A note consists of a title on a separate line and then the body of the note. The main interface for Deft is the Deft File Browser, which is simply an Emacs buffer that lists the note titles, the first few words of the body, and the last modification time. The principle operation in Deft is searching and filtering. Filtering is initiated by simply typing some text. Files that have a title or body containing that text show up in the Deft browser on the fly. It’s sort of reminiscent of how Ido interactively pares down the list of target files.

There are a couple of other features but Deft’s main strength is its simplicity. In that, it embraces the Unix principle of doing one task and doing it well (and in plain text, of course). Installation is trivial. Simply clone the source, stash it in the Emacs Lisp search path, and add

(require 'deft)

to your .emacs or init.el file.

If you’re already an Org mode user, org-capture and a notes.org file can accomplish the same thing but if you don’t want to bother with Org mode and want a simple and effective way of managing notes, Deft could be just what you’re looking for. The Deft home page at the above link has a nice write up so go take a look if you’re interested in a lightweight note manager.

Posted in General | Tagged , | 3 Comments

Printing In Emacs Lisp

Xah Lee has added another page to his excellent series on Emacs Lisp. This time it’s about printing in Emacs Lisp. Most of us who have written any elisp are familiar with the message function, which prints a message to the “*Messages*” buffer and echoes it to the minibuffer.

Often times, we want to write messages to some other buffer—the two posts on Xah’s Challenge are examples. The basic mechanism for doing that is to use with-output-to-temp-buffer in conjunction with the print, prin1, or princ functions. Head over to Lee’s post for all the details if you don’t already know them. It’s a nice summary of the various printing commands.

There are several excellent blogs that cover using Emacs (emacs-fu, Got Emacs?, Mastering Emacs, Xah’s Emacs Tutorial, and many others) but Lee’s Emacs Lisp Tutorial is the only one I know that regularly covers Emacs Lisp and how to use it to solve editing problems. Emacs Lisp is pretty much like other Lisps so anyone using Common Lisp or Scheme will be comfortable with most of it but the problem is that Emacs Lisp has tons of functions that are specific to the Emacs editing environment and none of those will be familiar to someone coming from another Lisp. That’s where Lee’s Emacs Lisp Tutorial is essential. He gives you real working examples and you see those commands in action.

Posted in General | Tagged | Leave a comment

Emacs 24 Features

Bozhidar Batsov over at (think) recently loaded the current development version of Emacs 24 and gives us a peek at its features. The post is a very nice look at what’s coming in the next version of Emacs and well worth a look by all Emacs fans. His writeup is fairly comprehensive—at least for the features he covers—so I won’t try to summarize it here; you should go read it yourself.

Batsov doesn’t say whether he is using it for day-to-day work or just playing around with it. I remember using the Emacs 23 development version long before it was officially released and never had any problems. It would be nice to know if Emacs 24 is at that state yet. I’m very happy with Emacs 23 so I don’t feel the need to jump into the new version before it’s completely baked but some of you may be waiting for one of those new features and feel differently. Be sure to let us know if you do adapt it for day-to-day use and how it works out.

Update: Asked and answered. Batsov comments that he has been using Emacs 24 for day-to-day work for about a month and that it’s rock solid. Anyone who can’t wait for those new features should give it a try.

Posted in General | Tagged | 7 Comments

The Greatest Software Ever Written

Over at InformationWeek, Charles Babcock asks What’s the greatest software every written? We all have our favorites, I suppose, but take a minute to think of your answer to that question.

Babcock begins by listing some of the things that make a particular piece of software great: it must represent a breakthrough and demonstrate technical brilliance; it must have “legs” and not be easily replaceable; and it must do the job it was created to do. With that in mind here are Babcock’s choices for 2 through 12:

2 IBM’s System R
3 Institute for Genomic Research’s gene sequencing software
4 IBM System 360
5 Java
6 Mosaic browser
7 Sabre airline reservation system
8 Macintosh OS
9 Excel spreadsheet
10 Apollo guidance system
11 Google page rank
12 The Morris worm

Take a look at the article to see the reason for these rankings. They are, it seems to me, reasonable choices. You or I might disagree about some or the order but they aren’t obviously wrong. That leaves the choice for number one—the greatest software ever written. Can you guess what it is?

If you look at the list the answer should be obvious by what’s missing: Unix. That’s not really a surprise but Unix covers a wide range. Just for starters there’s AT&T Unix, BSD Unix, and Linux. Babcock is specific; he chose 4.3BSD. Again, see the article for his reasons. I find them persuasive. What do you think?

Posted in General | Tagged | Leave a comment

A Quick Emacs Tip: zrgrep

Commenting on my post about Emacs and tar fles, Phil remarks that he likes the way Emacs keeps its source code gzipped and decompresses a file transparently when you open it. But he was unhappy that he couldn’t use 【Meta+xrgrep to search the code base. Then he discovered that he could do that with 【Meta+xzrgrep.

I didn’t know that and just in case any of you didn’t know it either, I thought I’d rescue it from the obscurity of the comment section and make it a stand alone post.

Update: Removed superfluous “the”

Posted in General | Tagged | Leave a comment

Moving To An Intermediate Point In An Emacs Buffer

Almost evry Emacs user is familiar with 【Meta+<】 and 【Meta+>】, the commands to move to the beginning and end of the current buffer. Today while browsing in Aaron Hawley’s excellent Emacs Reference Sheet, which I’ve written about before, I discovered that you can move partially toward the beginning or end by giving a prefix argument. Thus, 【Meta+5 Meta+>】 will move to the middle of the buffer. In general, 【Meta+N Meta+<】 will put the point N/10 of the way from the beginning of the buffer and 【Meta+N Meta+>】 will put the point N/10 of the way from the end of the buffer.

These certainly aren’t commands that you’ll use everyday but when you need them they are very helpful. They are another example of Emacs doing the expected thing that I wrote about yesterday.

Posted in General | Tagged | Leave a comment

Reading Tar Files With Emacs

I’ve been using Emacs for some time but am still regularly amazed at how it just does the right thing and in the expected way. Emacs has a well deserved reputation of having a steep learning curve and, indeed, like most Emacs users I’m still learning but it also has a simplicity and a “just works” quality that I haven’t found in any other editor.

Case in point: tar files. I do most of my work with OS X and don’t use any of the package managers so my normal procedure is to download tar files (unless there’s a git repository) and compile from scratch. Often times, it’s nice to know what’s in the tar file. For example, I have a tools directory and I untar into it to create a subdirectory for each project. Before doing that I always check the tar file to make sure it’s not going to spew a bunch of files into the top level tools directory. That’s easy enough to do with

tar -tvzf some_project.tgz

but Emacs gives us another way—a completely obvious and expected way. You merely open the tar file in Emacs with 【Ctrl+x Ctrl+fsome_project.tgz. This will give you a Dired style listing of the tar file but that’s not all. You can move the point to one of the files in the listing, type 【e】 or 【Return】 to load it into an editing buffer, edit it, and then save it back to the tar far—all without untarring the files. You can also delete and copy individual files.

All this works in the expected way; it’s not quite Dired but close enough that you can forget it’s not. It just seems natural until you think about what’s going on. First the file is compressed so Emacs has to decompress it, second Emacs has to understand the tar file format and extract the file you want to edit from the archive and then reinsert it. Finally, it has to recompress the archive. All of this is so simple and transparent that you could discover it accidently by inadvertently opening a tar file.

As I say, I’m always discovering some great new Emacs functionality that in retrospect seems so natural and obvious that I wonder why I didn’t “just know” it was there. That is until I think about what’s going on under the covers. Then I realize what a really great tool Emacs is.

Update: e → 【e

Posted in General | Tagged | 3 Comments

Workshifters

Today is Labor Day in the U.S. so I’d like to write about a phenomenon that has fascinated me for some time: workshifting. The term refers to the practice of people spending at least part of their time away from a traditional office. Often these people work for an otherwise conventional company but have arranged to work from home or, really, anywhere they like.

I first started paying attention to this movement after reading Mike Elgan’s article on the new Bedouins in 2007. The idea was that ubiquitous WiFi and other communication advancements had enabled a new tribe of digital nomads who conducted business from wherever they happened to be. The local coffee shop was a favored locale but some workshifters took it to the extreme, traveling all over the world and using their smart phones and laptops to conduct business pretty much as if they were in a conventional office setting.

My impression is that the first new Bedouins were primarily journalists and those involved in computer related technical fields such as software or Web development. Since its beginnings, workshifting has grown at a rapid pace. There are Web sites, such as workshifting.com devoted to it and people from many different occupations are joining the movement. Basically, anyone who isn’t a factory worker or in retail sales is a candidate, although many managers remain unconvinced.

Writing in the The Atlantic, Sara Horowitz, who founded Freelancers Union, suggests that the surge in workshifting freelancers is a new industrial revolution. Part of this is driven by the poor economy but the movement was growing even before the collapse and is likely attracting new members because of the freedom and enhanced lifestyle that it offers. One thing for sure, the traditional notion of working in an office for a single company for life is fast becoming a thing of the past.

In 2010, The Economist did a special report on the rise of workshifting and the changes it is bringing with it. One of my favorite stories from the report is of an executive at UBS who left his job to form his own consultancy with five other colleagues. At their first meeting they decided that the most urgent priority was to have everyone get a Blackberry, then to start contacting prospective clients. They also decided that at some point they should look into getting office space. The six firm members were busy running around the city and country, keeping in touch with email and IM and never got around to worrying about the office. Later they realized that they didn’t need or want an office so the consultancy became a “virtual company.”

As geeks, all this seems natural and inevitable to us. We understand the tools and many of us live a digital life regardless of our employment status. For the rest of the world, not so much. Managers, especially, are dubious. They worry about how they can manage if they can’t see what their employees are doing. The more forward-looking managers realize the many benefits to be had and have switched to a results oriented work environment (ROWE) style of management. ROWE is a good fit for workshifters and it’s gaining currency.

Workshifting is a really exciting phenomenon and I expect to see it become a large and important part of the economy in the near term. Some would argue that day is already here and that what lies ahead is that it will become the dominant type of employment. One thing for sure, the future is going to be interesting.

Posted in General | 2 Comments