Skip to main content


Showing posts from March, 2013

Automatic bookmarking of locations in Emacs

One of the things I find myself doing over and again in Emacs is returning to the last place I was editing a file. Sometimes that's because I've killed a buffer before I should have done (thinking I was finished), sometimes it's because I've exited Emacs and sometimes it's because I simply return to something a day or two later.

Since it was incredibly annoying to have to search for the last place I was working I created a simple system in Emacs that automatically remembers where I was and then lets me jump there by hitting C-l (obviously you can choose whatever key binding you like, I choose that because I never use C-l for its real purpose).

The automatic bookmarking works by using three Emacs hooks: when kill-buffer-hook or after-save-hook are called it records the current line number of the buffer in an internal hash table; when kill-emacs-hook is called it makes sure that the line number in each current buffer is saved and serializes the hash table to ~/.emac…

A simple illustration of Go interfaces

Go's approach to object orientation is somewhat different to the familiar 'hierarchy of classes'. In place of classes with methods, Go has interfaces. An interface specifies a set of behaviors (functions that can be called). If a Go type has that interface (i.e. has all the functions specified in the interface) then it can be used wherever that interface is required.

A commonly used interface in Go is io.Writer. An io.Writer interface is defined as follows in the io package:
type Writer interface { Write(p []byte) (n int, err error) } Any user-defined type that has a function with signature Write(p []byte) (n int, err error) is an io.Writer and can be used wherever an io.Writer is needed. For example, the bufio package can be used to create a buffered version of any io.Writer by passing it to bufio.NewWriter.
func NewWriter(wr io.Writer) *Writerbufio.NewWriter's argument is itself an interface (an io.Writer), so anything that has the Write(p []byte) (n int, err error…

Some Pig

In the past I've written about writing. In my previous blog post I recommended three books: On Writing Well, by William Zinsser. This book is an example of its own title. It's a delightfully well written book about writing that reads with the slippery ease of a Malcolm Gladwell. It's both enjoyable and informative. The AP Manual of Style. Although the AP book is about writing for newspapers it is full of useful advice about clarity. The fight for clarity is at the heart of non-fiction. Your goal is not to delight the reader with the breadth of your vocabulary, but to inform them about a subject in which you are claiming to be knowledgeable. News writing has to aim to be succinct, accessible and accurate; those are all good attributes for any non-fiction writing.  The Elements of Style, by Strunk and White. The surprising thing about Strunk and White is that I can pick it up after years and years of owning it and rediscover its lessons. If you only buy one book from my list …