Eshell

Back in February I wrote about switching from bash to John Wiegley’s eshell. I’ve been really happy with eshell but have used it pretty much as I would bash. Recently, I saw a tweet that pointed me to this Mastering Emacs post. As usual, Mickey is the go to guy for information on how Emacs works.

Mickey remarks that although eshell is awesome, the documentation is lacking. He proceeds to fix that with a long post that discusses many of the ways that eshell is different from (and often better than) bash. In the comments, Wiegley makes an appearance and points out a few things that Mickey missed.

If you aren’t already using eshell I urge you to give it a try. I find that I’m much less apt to bring up a separate shell than I was when I was running bash inside Emacs. If you’re not sure, give Mickey’s post to look to see what you’re missing. If you’re already using eshell, you should check out the post too. It’s full of useful information that will help you take full advantage of a really great Emacs mode.

Posted in General | Tagged | 3 Comments

The Emacs defadvice Macro

Evgkeni Sampelnikof has posted a nice introduction to defadvice. Emacs is all about having it your way and making it easy to do so. Very often it’s convenient to change the behavior of a built in command and since Emacs has no secrets we can always plunk a copy of the command’s source code into our .emacs file and modify it to produce the desired behavior. Unfortunately, that strategy produces a maintenance problem and adds to the clutter of your (probably overly cluttered) .emacs file.

In many situations, a better way is to use the defadvice macro. It allows you to perform some action before and/or after the command is executed. See Sampelnikof’s post for the details. An excellent example of when you might want to use defadvice was given by Magnar Sveen in his What the .emacs.d!? post about restoring the screen configuration after a call to Magit. That’s a tremendously useful modification to the magit code and I can’t imagine any magit user not wanting it. Happily, it trivial to implement with defadvice.

Posted in Programming | Tagged | 1 Comment

So True

Don Taylor has it just right in this tweet. Well, maybe more than just a useful editor.

Posted in General | Tagged , | Leave a comment

DSLs

I have a long standing love affair with Domain Specific Languages (DSLs). Back when I was writing in C, I wrote several compilers and associated interpreters for various DSLs. This mainly involved using fairly heavyweight tools like lex and yacc and hand writing the virtual machines.

When I moved to Lisp, it all became much easier. Part of the Lisp culture is “building the program up” to make what is, in effect, a custom DSL that is used to implement the program logic. Recently, Nic Ferrier tweeted about a video from Rainer Joswig concerning building a simple DSL to turn file entry descriptions into objects. This is a really excellent video and I recommend it to anyone interested in Lisp and DSLs.

Before you watch the video, you should take a look at the article (from Martin Fowler) that inspired it. It will make Joswig’s presentation easier to follow. It will also help you realize how much better Lisp is at this sort of thing than C# or Java.

Posted in Programming | Tagged , | Leave a comment

Emacs vs. Vim

Steven Harms has1 a nice take on the Emacs/Vi holy wars. His idea is that the two sides are actually talking about different things. As we’ve discussed many times here, Emacs is about the ultimate customizable work environment. It provides a modern day Lisp machine where everything is under your control. Emacs users are famously loath to leave Emacs and move as much functionality as possible into it.

Vi(m), on the other hand, is proudly simply an editor. They consciously eschew the Emacs “do any- and everything” philosophy. Their philosophy is do one thing and do it well. That one thing is, of course, editing.

Thus, when the two sides meet in battle they are really talking about different things: Emacs users about a customizable work environment and Vi(m) users about an editor. It’s no wonder they can never agree. Of course, a lot of it is probably just the geeks’ love of arguing about who’s tool is better but Harms’ take makes it sound so much more high minded.

Footnotes:

1 Actually, had. After I wrote this I noticed that his post is from 2005. It’s no less on point for that, however.

Posted in General | Tagged | 2 Comments

Emacs Configuration Organization

Sometimes I feel lonely. As many of you know, I keep my emacs configuration in a single init.el file1. Almost all the Emacs hackers that I respect have a complicated Emacs configuration split among multiple files.

Finally, I’ve found someone who agrees with me. Donald Curtis, also known as Milkypostman, the proprietor of the Melpa archive, has a post in which he advocates keeping your Emacs configuration in a single file. His configuration is well organized and easy to navigate. It shows, I think, how a single-file Emacs configuration can be easier to use and navigate than an equivalent multi-file version. You mileage may vary, of course, but at lease I don’t feel so lonely.

Whatever you predilections for Emacs configurations, you should take a look at Milkypostman’s post. He’s got some good ideas (such as his after macro) that are useful no matter how many files you have in your configuration.

Footnotes:

1 Actually I have separate files for OS- and machine-specific configurations that get loaded when Emacs starts on a particular machine or OS.

Posted in General | Tagged | 2 Comments

Opening the File at Point

Xah Lee has posted a nice bit of Elisp that allows you to open the file at point. Of course, Emacs has the ffap command to do that but, as Lee points out, there are a couple of (small) problems with it. Lee’s code takes care of opening not just files but also URLs.

If you find yourself needing to do this more than once a month, it may be worth your while to add Lee’s code to your .emacs or init.el file. I especially like the way it handles regular files and URLs. If you have special related needs, it would probably be easy to adapt Lee’s code to meet those needs as well.

Posted in General | Tagged | 1 Comment

Emacs Resources

The folks over at The Emacs subreddit have posted a very nice list of Emacs resources. They’ve got distributions, tutorials, starter kits, blogs, and references. They’re taking suggestions for additions so let them know if they missed anything important to you.

I like this type of thing because it gives me a single place to go when I’m looking for subject matter about a topic. It means I need only remember—or bookmark—a single page rather than potentially hundreds of them. We have resources like EmacsWiki, of course, but that offers a more in depth look at certain areas of Emacs and is harder (although possible) to use to find, say, Emacs videos. The Emacs resource list on reddit is still rather short but as I mentioned they’re taking additions so it has the potential to grow into something more comprehensive.

Posted in General | Tagged | Leave a comment

A Fast Open for init.el

Like me, Bozhidar Batsov is always fiddling with his init.el file. As a result, he’s devised a way to open it quickly. He wrote a bit of Elisp to load it and bound the Elisp to the simple key sequence 【Ctrl+c I】. That’s a pretty nice solution and one that Irreal readers might expect me to adopt.

I, however, have a different strategy. I have 4 or 5 files that I use all the time. I have them bookmarked so I can load them easily but I don’t need to do that very often because I just keep them loaded. I use desktop-save-mode so they stay loaded even across Emacs invocations. Then when I want to examine, say, init.el it’s just a matter of 【Ctrl+x bin or maybe just 【Ctrl+x bi depending on what ido has in its cache at the moment. That’s not as fast as Batsov’s 【Ctrl+c I】 but it’s fast enough1.

One of the commenters to Batsov’s post suggests using the bookmark facility with a label of, say, i for init.el. Then you can open init.el with 【Ctrl+x r b i】. That gives us at least 3 ways of solving the problem, which is really the point. With Emacs you can solve problems in a way that’s comfortable for you. How do you solve the problem of opening frequently accessed files?

Footnotes:

1 Basov’s solution opens init.el in another window so his solution is faster still if you have that requirement. If I needed that, I’d use 【Ctrl+x 2】 first. If I always wanted a separate window, I’d probably adopt Batsov’s solution.

Posted in General | Tagged | 4 Comments

The Coding Standard From Hell

You say you hate your organization’s coding standards? You say they make the code harder to understand and maintain? You say they could only have been devised by a particularly moronic version of the pointy haired boss? Stop your whining and let John Graham-Cumming show you what a real coding standard from hell looks like.

Really, it’s hard to see what they could have been thinking. I understand the need of some people to have a detailed plan before starting to cut code but jeez! It makes you wonder (in a staring at a train wreck sort of way) what the rest of the standard looked like. But, of course, it was the government.

Posted in Programming | Leave a comment