Writing an Emacs Major Mode

Wilfred Hughes has a nice post on writing a major mode for a new language. As Hughes demonstrates, it’s pretty easy to get started but there’s lots of details and nooks and crannies to worry about.

His post shows how to get started and points out enhancements that you’ll want to make as you grow the mode. A minimal implementation should have syntax highlighting and indentation. Fortunately, it’s pretty easy to get those working, especially if you use the SMIE engine to help with indentation1.

As you build out the mode, you’ll want to add things like completion, Eldoc, and Flycheck. Hughes’ post doesn’t tell you how to program these features but it does point you in the right direction. If you’re interested in writing a major mode for a language, this post is well worth reading.

Footnotes:

1

But be sure to follow the link in Hughes’ post to Steve Yegge’s musings on how hard indentation really is.

Posted in General | Tagged | Leave a comment

Emacs and Exchange Web Services

For those of you condemned for past sins to use the Exchange calendar system, this can help you keep things in the family. Actually it’s an Emacs interface for the entire Exchange Web Services API. Seems like it could be useful for those whose world straddles Emacs and Exchange.

Posted in General | Tagged , | Leave a comment

Engine Mode

How often have you wanted to Google some term in the document you’re working on, or look up the documentation for a function? Many of us have a few Elisp functions to do this but you end up with a lot of duplicated code and the corresponding maintenance problems.

Harry Schwartz, who we know from his chat with Sacha, addresses that problem in his latest talk to the NYC Emacs Meetup. The talk, Searching the web with engine-mode, is about Schwartz’s engine-mode. What happens is that you define a site you want to search along with a single key that tells engine-mode to query that site. There is a key prefix, nominally 【Ctrl+c /】, that invokes engine-mode and waits for the final key to specify the site.

I like this approach because rather than have a bunch of complicated key sequences to memorize, you just pick a key that suggests the site: 【d】 for DuckDuckGo, 【g】 for Google, 【w】 for Wikipedia, and so forth.

You can see Schwartz’s configuration here. As you can see, he has a lot of sites defined. It would be a pain to write separate Elisp for all of them so engine-mode is a win if you like to make such searches.

Schwartz shows the details in the video so it’s worth watching. It’s about 18 minutes.

Posted in General | Leave a comment

Keeping the Minibuffer Cursor Out of the Prompt

Have you ever been annoyed when editing in the minibuffer and you accidently move the cursor into the prompt? If so, here’s a tip from Xah Lee on how to avoid it.

Posted in General | Tagged | 1 Comment

SBCL 1.2.10

SBCL 1.2.10 is out and available at the usual place. This month’s release is mainly bug fixes, although there is one enhancement. You can get all the details from the NEWS page.

As usual, the system built and ran the regression tests without incident on my OS X 10.10.2 systems. Rather than give you my usual monthly paean to the outstanding team of SBCL developers, I’ll leave you with these observations from a satisfied customer.

Posted in Programming | Tagged , | Leave a comment

News From the Emacs vs. Vim Front

Via reddit: an oddly satisfying exchange.

Posted in General | Tagged | 1 Comment

Org Capture Video

Jonathan Magen recently gave a talk to the New York Emacs Meetup group on using Org capture. His setup is a little different from mine so it was interesting to see how he did things.

If you’re an Emacs user and not taking advantage of Org capture, you’re really missing out. I set it up when I first starting using Org mode using Bernt Hansen’s excellent Org Mode — Organize Your Life in Plain Text as a guide. His work flow is a bit different from mine so I wasn’t really taking full advantage of it until recently when I added capture templates for blog ideas, my journal, and other specialized tasks.

Those capture templates have really made a difference. It’s easier and faster to capture data and because they are customized to my work flow the end results are more useful to me.

It’s definitely worth spending some time learning the capture system. A good way to get a feel for it is with Magen’s video. It’s about 15 minutes so you don’t need to block out a lot of time.

Posted in General | Tagged , | Leave a comment

Hunting for Bugs in init.el

If you’re an Emacs user and have a non-trivial .emacs or init.el you have almost certainly run into the situation where you make a change or upgrade a package or Emacs and things stop working. I see questions about how to troubleshoot this from n00bs all the time.

Invariably, the advice is to do a binary search on your configuration file by commenting out half of it and seeing if the errors persists and then commenting out half of the other half if so. That process converges in \(\log_{2} \,n\) time for \(n\) lines. That’s pretty quickly for most .emacs or init.el files but is still a pain.

Happily, the prolific Artur Malabarba—when does he have time to work on his thesis?—has come to the rescue with elisp-bug-hunter. If you get an error while loading Emacs, just run

M-x bug-hunter-init-file RET RET

and bug-hunter will do the binary search for you. You’ll get a nice report showing where the error occurred. That’s pretty nice but bug-hunter is even more flexible. Suppose Emacs loads without error but some aspect doesn’t work correctly. If you can write an assertion to detect the error, bug-hunter can still find the problem.

The example Malabarba gives is figuring out how cl.el is getting loaded. To do that, you just run

M-x bug-hunter-init-file RET (featurep 'cl) RET

and bug-hunter will tell you where it’s getting loaded. That very issue has come up with my own init.el file so I ran that example and discovered that package-initialize was loading the library. That’s very nice indeed. Malabarba gives other examples in the README at the link.

I’ve loaded bug-hunter now so that it will be available the next time I need it. You could probably get it loaded after the fact but why make life harder than it needs to be?

Posted in Programming | Tagged | 4 Comments

Killing dired Buffers

Here’s a nice tip on how to get rid of a dired buffer by killing it rather than burying it.

Posted in General | Tagged | Leave a comment

A Bit of Wisdom from John Carmack

For an wonderful and revealing example of using s-expressions for data interchange, see the paper I discussed in this post from my old blog.

Posted in General | Tagged | Leave a comment