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

Ampersands

This post is a little outside the usual Irreal sphere of interest but its subject matter is so delightfully geeky and interesting that I couldn’t resist writing about it. Over at the hot word (on Dictionary.com) they ask, “What character was removed from the alphabet but is still used every day?” The answer, of course, is the ampersand.

It turns out that the ampersand was once the 27th character of the alphabet. That’s vaguely interesting in a Jeopardy answer sort of way but it’s the rest of the story that really captured my imagination. The first surprise is the origin of the shape of the character. By the first century Romans were using cursive writing so the linked e and t of et, Latin for and, came to take on the shape of the modern day ampersand. You can see that clearly on this Adobe page about the ampersand. The hot word post recommends the William Caslon font (Figure 6) as a particularly striking example of this but I find Figure 9 even more so.

The second surprise is how the character came to be called an ampersand. In the early 1800s, when the ampersand was still considered part of the alphabet, school children reciting their ABCs would end with “X, Y, Z, and per se and.” Per se means “by itself” so they were saying, “X, Y, Z, and by itself and.” The hot word explains that that was to avoid the clumsy ending “X, Y, Z, and.” Over time the “and per se and” became slurred together into the word ampersand.

There’s many more interesting facts in the hot word post so you should go on over and take a look. Among other things, you’ll learn that the slurring that produced “ampersand” from “and per se and” is called a mondegreen. If you follow the link they give, you’ll discover where the name mondegreen came from. It’s another interesting story.

Posted in General | 1 Comment

Smex

Back in July I wrote about using aliases to replace longer, hard to remember command names. Several of the commenters said that I should use smex to bring the wonders of Ido to extended commands. I finally got around to doing that and am now wondering why I waited so long. Now instead of relying on the qrr alias for query-replace-regexp I just type 【Meta+xqreg to get it. Sure, it’s a character longer but the same sort of thing works for all the commands, not just the ones I have aliases for. If you’re into adventure games, a little experimentation will usually find a shorter sequence. For instance 【Meta+xqex will also execute query-replace-regexp but the nice thing about smex is that you just need a general idea of what the command is to find it within 3 or 4 characters.

You can get smex via ELPA or from Github. Installation is simple. Just stash smex.el somewhere in your elisp load path and add

(require 'smex)
(smex-initialize)
(global-set-key (kbd "M-x") 'smex)
(global-set-key (kbd "M-X") 'smex-major-mode-commands)
(global-set-key (kbd "C-c C-c M-x") 'execute-extended-command)

to your .emacs or init.el file.

The key bindings are:

key binding action
Meta+x find all commands
Meta+X find mode specific commands
Ctrl+c Ctrl+c Meta+x old extended command functionality
Posted in General | Tagged | 6 Comments

Opening Frequently Accessed Files In Emacs

While browsing around in the EmacsWiki, I came across a nice way of quickly opening frequently accessed files. The idea is to put the target file in a register and then jump to the register. For example, I frequently open my steps file to record my walking and a tax file in which I list deductible expenses. I can preload the s and t registers with the locations of these files by adding the following to my init.el file.

(set-register ?s '(file . "~/medical/steps.org"))
(set-register ?t '(file . "~/org/tax2011.org"))

Then I can open them by jumping to the appropriate register. For instance, to open the tax file, I would type 【Ctrl+x r j t】.

To be sure, you can do the same thing with bookmarks and even have more descriptive names but I like this solution because it’s just a few keystrokes. Doubtless, Xah Lee would chide me for wasting keystrokes by not using function keys for this sort of operation but given the Mac keyboard it’s a method that works well for me.

Registers are a nice feature of Emacs and it’s worth investigating their uses. Perhaps I’ll write more on the subject later.

Posted in General | Tagged | 2 Comments

The End Of Handwriting?

I’ve written before on how I have pretty much stopped writing anything with pencil/pen and paper. These days the only things I use a pen for are to sign credit card receipts and the very occasional check. For all that, I assumed that I was an outlier, perhaps bordering on the eccentric. But maybe not; Anne Trubek has an interesting article over at Miller-McCune in which she argues that Handwriting Is History.

It turns out that people are very emotional about the subject. Some invest good handwriting with a moral dimension and equate the end of handwriting with the end times. An earlier article by Trubek along the same lines encountered vehement opposition and extremely hostile comments. Still, there’s no denying that cursive handwriting is on the wane—I haven’t used it since elementary school—and children today simply aren’t learning it.

That’s interesting but the larger question is whether even printing will eventually die out. On the one hand, as my own experience shows, it’s perfectly possible to get by without pen and paper. Indeed, I believe you’re better off that way. You can get your thoughts recorded much more quickly and keep them around in searchable form without the clutter of files and stacks of paper. Already, things like the Starbucks iPhone app are pointing the way to the end of credit card receipts and it’s almost certain that the next generation of smart phones will have NFC capabilities that will hasten the demise of the credit card system as it exists today.

On the other hand, it’s hard to imagine doing mathematics without pencil and paper. Perhaps that’s just a failure of imagination on my part—look at Mathematica, after all. If I had to guess, I’d bet that handwriting is heading where physical books are: neither will die out completely but will survive in niches that the ordinary person will find quaintly charming. What do you think? Will handwriting die out or will it, like rock and roll, always be?

Posted in General | 5 Comments

Traveling With An iPad

I just got back from another family visit, this time to upstate New York. I was well out of Irene’s path and except for a rainy Sunday wasn’t affected at all—I thought. Upstate New York wasn’t affected but New York City certainly was: JFK shutdown causing 1600 flight cancellations.

I’ve written before about traveling with an iPad as my only computer but this time I had to completely rearrange my travel itinerary. I was flying out of Syracuse and there were no flights to Tampa so I had to fly to Orlando. That meant arranging for a rental car to drive to Tampa from Orlando. Because the flight left early, I booked a room near the airport so my family wouldn’t have to get up at 3:30 to make the hour and a half drive to Syracuse.

I’m happy to report that I was able to all this easily with the iPad. I had to call the airline directly to rebook the flight and I just entered the new information into FlightTrack Pro manually and pushed it to Tripit. I made the car and motel reservations on line and forwarded the email confirmations to Tripit. When I finished, I had the new itinerary in Tripit complete with confirmation codes and other essential information. All of that was mirrored automatically to my iPhone for instant reference when needed.

As it happens, my family has WiFi but even if they didn’t, the broadband connectivity on my iPad would have enabled me to do all this. For that matter, I suppose I could have done it all on my iPhone but the iPad certainly made for a more pleasant experience.

This was only the second time I’ve traveled with just my iPad but after this trip I feel pretty comfortable doing so. I missed Emacs and my development environment but I probably wouldn’t have used them anyway. I shudder to think what a nightmare making a new itinerary would have been without my iPad and a few key apps like FlightTrack Pro and Tripit. The only phone call I had to make was to the airline (with a 30 minute wait for a representative). Everything else was handled quickly and easily on-line.

Posted in General | Leave a comment

Listing Files On A Remote Server With Emacs

I use TRAMP all the time to edit files on a remote machine: it’s quick, easy, and pretty much transparent. I just learned something new that in retrospect should have been obvious. You can obtain a listing of remote directories simply by opening the directory.

Normally, when using TRAMP, you specify a file 【Ctrl+x Ctrl+f/host:directory/file and Emacs fetches the file for you to edit and then copies it back to the remote host when you save it. But if you specify just a directory, 【Ctrl+x Ctrl+f/host:directory, Emacs will either open a Dired buffer for that (remote) directory or show you a list of files in the minibuffer. I haven’t figured out the exact rule but it appears that the first time you go to the remote host you get the Dired buffer. After that you get the list of files. If you want the Dired buffer you can always get it with 【Ctrl+x d/host:directory.

The nice thing is that this Dired buffer acts just as a local one does. You can drill down into subdirectories and choose a file to edit as normal. All the usual Dired commands work just as if you were in a local directory: you can search, mark, copy, delete, and so on.

Considering that my usual procedure is to SSH into the remote host and run ls to find the exact name of the file that I want to edit, this is a real time saver. Just another example of the power of Dired, this time assisted by TRAMP.

Posted in General | Tagged | 3 Comments

Security and Unicode

I’ve written before about the wonders of Unicode but this post is an example of its dark side. Over at the Microsoft Malware Protection Center there is an interesting post about the use of Unicode by malware. It seems that the trojan TrojanDropper:Win32/Vundo.L hijacks the Russian social networking sites vk.com and vkontakte.ru and redirects them to another—presumably malware, the story doesn’t say—site.

The normal way of doing this is to add an entry to the hosts file (%SystemRoot%\system32\drivers\etc\hosts) but when they checked the hosts file it was clean—no entries for the Russian site. Then they displayed hidden files and discovered another hosts file that had been corrupted. How could this be? You can’t, of course, have two files with identical names in the same directory. By now, you’ve guessed the answer: the visible hosts file had the o replaced with the Unicode character 0x043E, which is a Cyrillic character that looks like the Roman character o. That meant that TCP/IP ignored the “clean” hosts file because it had the wrong name and ussed the hidden one instead.

I’ve heard of this trick being used in URLs to snare the unwary into going to a rogue site that appears to be legitimate but this is the first time I’ve seen it used this way. A very simple but effective trick.

Posted in General | Tagged | Leave a comment