Emacs and the Bible

By awagner

So one thing I’ve been thinking a lot about lately is using the power of technology for Bible study. I have many ideas for this, which I’m not going to expound on right this minute. However, I am going to wax uber-geeky and tell a bit about how I used Emacs to re-format a text-version of the Bible. I won’t be offended if you don’t read this post, particularly if you’ve never heard of Emacs or XML, because you won’t get it anyway.

My desired end result was a Bible in a very simple XML language. So I found a plain-text version of the Bible on http://www.o-bible.com/dlb.html (I grabbed the KJV, but now that I know what I’m doing, I’ll probably do the BBE too.

Each verse of the Bible is in a format like the following:

Ge1:1 In the beginning God created the heaven and the earth.

What I wanted was a format like the following:

<book name="Genesis">
<chapter>
<verse>
In the beginning God created the heaven and the earth.
</verse>
</chapter>
</book>

(for the record, escaping markup in wordpress is exhausting.)

So, first thing was to at least wrap each line in a verse tag. There are 31000+ verses in the Bible. There’s no way I was going to manually try to do that 31000 times. Not a chance. That’s where Emacs came in! Emacs has awesome macro-recording and -playback capabilities. All I did was wrap a line in <verse>…</verse> tags, and then say “oh, could you do that 31000 times for me please? Thanks. Done.

Next we need book tags. The macros get a little trickier here. Now we need to do a search for “1:1 “, parse out the book abbreviation with a regular expression, go to the beginning of the line, insert a blank line, and put “<book name=’book_abbreviation’>” in it. Oh, and repeat it 66 times or so.

Now come the chapter tags. By this time, we’ve got the hang of it though, we just grab all the “:1 ” occurrences, back up, and stick a chapter tag in. And repeat 1200 times. This does introduce a small issue with the first chapter of each book, but another little macro cleans that up easily.

Finally, we write one more little macro to find each verse and strip off the little prefix at the beginning. And repeat 32000 times.

This was a fun little process for me, and it got me quite adept at emacs macros. I’m not encouraging anyway to learn Emacs just for this purpose (unless you’re using vim), just recording for posterity…

One Response to “Emacs and the Bible”

  1. Jason Hart Says:

    Nice job!

    Have you ever looked at the ESV’s API? It’s pretty slick, the only problem is, you can’t store a copy locally.

Leave a Reply