Tips on Being Productive with Emacs

Back in 2009 Phil Sung taught a short course on being productive with Emacs. The slides from the course (1, 2) are still available and well worth a look. Often times, slides from a talk without the actual presentation aren’t that useful but I found it easy to follow these. They start with the usual basic movements, move onto more complex actions such as searching and replacing, binding commands to keystrokes, and keyboard macros. Finally, they cover basic Elisp and how to write your own functions.

The GNU Guided Tour of Emacs is based on these slides and is also worth a look if you haven’t already seen it. You might also want to check out Sung’s Ten Essential Emacs tips. A slightly longer-form exposition of some of the same areas covered by the slides. Finally, you can read all his blog posts with an Emacs tag. Those posts contain a number of useful tips.

Posted in General | Tagged | Leave a comment

An Emacs Style Guide

Bozhidar Batsov, proprietor of Emacs Redux, is starting an interesting new project: The Emacs Lisp Style Guide. The idea is to create a community contributed set of rules for “good Elisp form.”

Normally, I’d hate that sort of thing. Almost always, style guides end up encoding silly ideas like

if (3 != x)  /* constants before variables in C if statements */

or even the incredible coding standard from hell. Throughout my career, I mostly ignored stuff like that. Oddly, though, I find myself in agreement with Batsov’s guide so far. That’s probably just because I already do things pretty much the way he proposes and there are a couple of good ideas that I hadn’t thought of like naming unused lexically scoped local values with a preceding underscore

(lamba (x _y) (* x x))

Old timers are going to do what they’ve always done, of course, but the guide has lots of good advice for less experienced Elispers. The rules are mostly what experienced Lispers do so using them helps promote clear, easily understood code.

Take a look at the guide and let me know what you think. And, of course, if you think something is missing or see something you think is wrong, add your voice to the discussion. It is, after all, a community effort; Batsov has just done the heavy lifting to get things rolling.

Posted in Programming | Tagged , | Leave a comment

Memory Reallocation Revisited

Back in January I wrote about a charming result concerning how much memory should be increased when reallocating. Via Artur Malabarba, I came across a tweet by Wilfred Hughes

pointing to Facebook’s implementation of the idea. The FBVector.md file at the link explains why they use a factor of 1.5 instead of 2 (it misses the beautiful result about the golden ratio, though).

Their implementation of the C++ std::vector library has other optimizations, which are also interesting. If you’re working in C++, you should definitely give it a look.

In my original post, I remarked that “none of this is of great import.” The folks at Facebook have shown that that was wrong.

Posted in Programming | Tagged | Leave a comment

Truism of the Day

Posted in General | Tagged | Leave a comment

Progress Indicator for Org-Mode Code Blocks

Via Grant Rettke, here is a nice snippet of code from John Kitchin that gives a visual indication of when an org-mode code block is executing. It’s just a defadvice around org-babel-execute-src-block so it’s easy to modify to suit your preferences.

Most of my code blocks execute more or less instantly so I would have limited use for this but if, like Kitchin, you have long running processes, it’s a nice hack to let you know the status.

This is another example of how Kitchin is automating his life with Emacs. Happily, the rest of us benefit from his work as well.

Posted in General | Tagged , | Leave a comment

Temporary Syntax Tables Revisited

The other day, I wrote about Xah Lee’s post on temporary syntax tables and the with-syntax-table macro. Subsequently, Lee discovered a nasty side effect that he wrote about on the G+ Emacs Community site. The problem was that his code

(with-syntax-table (standard-syntax-table)
  (modify-syntax-entry ?\« "(»")
  (modify-syntax-entry ?\» ")«")
  ;; 
  )

modified the original standard syntax table for all buffers.

The problem is (standard-syntax-table) doesn’t copy the standard syntax table; it just returns a pointer to the standard syntax table object. This is the same thing that happens if you assign a list to a variable:

(setq x '(1 2 3))
(setq y x)
(setf (car y) 5)
(message "x is %s" x)

returns

x is (5 2 3)

because x and y refer to the same object.

What we need to do is first make a copy of the standard syntax table. Happily, the copy-syntax-table function does just that1 so if we evaluate

(with-syntax-table (copy-syntax-table)
  (modify-syntax-entry ?‹ "(›")
  (describe-syntax))

the ‹ is described as an open bracket but if we open a new fundamental buffer and call describe-syntax it is described as punctuation, as expected.

Lee solved this problem by creating a new syntax table with make-syntax-table and added his definitions to it. You might think that Lee’s solution is incorrect because the other syntax definitions will be missing from his new table but it is correct because make-syntax-table will create a table that inherits from the standard syntax table (or whatever table you specify).

Footnotes:

1

copy-syntax-table copies standard syntax table by default but you can specify a table explicitly if you want to start with some other table.

Posted in Programming | Tagged | Leave a comment

Sacha Chats with Mickey

Sacha Chua has her latest Emacs chat up. This time it’s with Mickey Petersen proprietor of the excellent Mastering Emacs. If you follow the Emacs scene at all, you will be familiar with Mickey and his definitive articles on the ins and outs of Emacs.

Mickey came to Emacs pretty much because he was told all the cool kids use Vim. In the intervening 10 years he’s worked to master Emacs and share his knowledge with the rest of us through his blog. Watching him use Emacs you can see that mastery in action. He navigates through files so quickly and easily that it’s hard to follow the action.

One of the things that impressed and inspired me was that he tends to think in term of language constructs rather than characters. Thus, for example, he navigates by and manipulates s-expressions. That’s an attitude that I want to cultivate; it can’t help but increase my editing speed and efficiency.

The chat is about 53 and a half minutes so plan accordingly. As with all of Chua’s chats, you’re sure to learn a few things. For example, I learned the efficient way to backwards kill an s-expression.

Update: Sacha has a transcript of the chat up.

Posted in General | Tagged | Leave a comment

Transposing Words

Howard Abrams has a nice video on transposing words in Emacs. You might think that there’s not much to say about the subject: just type 【Meta+t】 and you’re done. Of course there’s also the fact that you can use it to “pull” a word towards the end of the line by repeated invocation of the command or by using a prefix number but that’s also well known.

Abrams explores an interesting edge case. What if you’re at the end of the line? He’s got an actual use for that. Suppose you’re typing along and realize you forgot a word

The brown fox

Rather than backing up and inserting the missing word, you can just type it at the end

The brown fox quick

and then type 【Meta+t Meta+t】 and quick gets inserted in the proper place.

That’s a nice trick that takes advantage of a side effect of transpose-words and you can use it as is. But Abrams shows how to advise transpose-words so that it handles this case with a single invocation. That means you just type 【Meta+t】 as usual and Emacs does the right thing.

The video is only 8 minutes so you can watch it whenever you have a few minutes. Very nice. Even if you don’t add the advise, it’s worth knowing the trick.

Posted in General | Tagged | 1 Comment

SBCL 1.2.3

The latest version of Steel Bank Common Lisp, 1.2.3, is available at the usual place. As always, it built without problem and successfully ran the test suite. ASDF has been upgraded to 3.1.3 and there are a couple more enhancements and some bug fixes as well. Check the NEWS page for details.

As Christophe Rhodes remarked, this month’s release is less exciting (read controversial) than last month’s. Regardless, SBCL is an excellent Lisp environment that gets better and better with each release.

Update: months → month’s

Posted in Programming | Tagged , | Leave a comment

Temporary Syntax Tables

Xah Lee has a nice post on how to temporarily modify a syntax table. It’s not something you want to do everyday, of course, but the example Lee gives is a real-world case.

It turns out that it’s pretty easy. Just use the with-syntax-table macro and you can change the syntax table in a way useful for the rest of the code in the macro’s body. When control exits the macro expansion, the old syntax table is restored. You can also use the macro to temporarily switch to a different syntax table. If the foregoing seems opaque, the example in Lee’s post will clear things up.

I didn’t know about the with-syntax-table macro so this post is my way of writing it down so I won’t forget. I’m sure I won’t need it often but when I do, it’s just the thing.

Posted in General | Tagged | Leave a comment