As you probably know by now, I am writing an intermediate textbook on Emacs Lisp, entitled Hacking your way around in Emacs. Last time I mentioned that I’d like to write something about the contents of the book. So, here it is. (Keep in mind that things may still be subject to some changes, though – the newest of them came to my mind today in the morning!)
Most programming courses/books/tutorials these days are about writing a to-do list. I could do the same, but I decided to do something else instead. In my book, every chapter will be devoted to developing one tool which is potentially helpful when using Emacs. I assume that the reader is already an Emacs user, familiar with its philosophy and some basics of Elisp. This means that s/he uses Emacs for some writing – be it email, Org-mode documents, wiki pages for some technical project or a novel. I don’t necessarily assume any experience in programming apart from the desire to learn Emacs Lisp, so most of the tools developed throughout the book are connected with writing in a natural language (or at least are language-independent). The very first command we write is a command to move the line at point up or down – something very useful in programming, but also when editing bullet point lists etc.
The second chapter of the book, which will most probably be also the longest one, is perhaps also the most interesting part from a user’s perspective. We develop a pretty sophisticated tool for reordering a sentence – in a sense, transpose-words
on steroids. This is probably not something you would use many times every day, but I felt a need for that many times when editing (editing, not writing!) documents, written either by me or by someone else. This is also a great opportunity to show numerous features of Emacs and Emacs Lisp – both pretty fundamental ones, like (in no particular order) anonymous functions (as arguments to other functions), destructive functions, interactive
codes, working with the region, narrowing, defining a minor mode, and more advanced, like text properties, overlays or catch
/throw
.
The third chapter is going to be something aimed more at programmers – a tool to count source lines of code. It is primarily geared towards Elisp, but can be used with other languages, too. We start with a first approximation, where we just count all non-blank lines in the buffer, and then proceed to make this more and more complicated - first excluding the comment-only lines and then docstrings. This enabled me to show a few useful techniques, like using higher-order functions (again), piggy-backing on Emacs syntax-awareness and condition-case
. We also learn how to read the “backtrace” Emacs shows when it encounters an error.
The rest of the book is still a bit fuzzy at the moment – there will probably be a chapter touching font-lock and regular expressions, and I also think about a chapter with a tool to help putting repetitive fragments into emails (which I am going to use to show a very basic Elisp macro). I also have some sketches regarding debugging using Edebug, and the thing I mentioned that occurred to me this morning is using Cask.
And this is pretty much it. If you think I missed something important – well, maybe I did. Emacs and Elisp are huge, a comprehensive textbook would probably require years of work and thousands of pages. (At the moment I am writing this, the pdf file of the GNU Emacs Lisp Reference Manual has 1337 pages – how cool is that, by the way? – and a proper textbook would probably need two or three times as much.) There are also things I deliberately omitted. What I hope to accomplish instead (as I said in an earlier post) is to prepare the readers to start coding on their own and using the reference manual themselves.
If you think this is interesting, go check the book on Leanpub – you can download the first chapter for free, and buy the rest (and you don’t risk much – Leanpub has a “money-back-with-no-questions” policy if you are not satisfied). I estimate that about 40 to 50 percent of the book is already written. (And yes, I told about 40% a month ago – but that was before I decided to include some more stuff… I still plan to finish it around September, though.) I also post updates about twice a month, and next update will contain actually usable code for reordering words I mentioned above!
Also, if you think I omitted something really important, or if you think the book should be completely different – or if you like it as it is – definitely tell me! Any feedback will be very appreciated.
CategoryBlog, CategoryEnglish, CategoryEmacs, CategoryEmacsBook