Need to convert some text from one programming language (or markup language or format) to another? It can betempting (and fun) to write a script that converts the whole job “automagically,” or maybe you can find a converter somewhere. But if the original file was hand-coded or is so complex that parts of the conversion are devilishly hard to get right, automating the task can take more time to perfect than it saves you. And unless you have an automated validator to check that the conversion was done correctly, you may have to inspect the result line-by-line anyway.
So, if doing the job automatically makes your head hurt too much (or if you’d rather be playing a game of Freeciv, http://www.happypenguin.org/), consider automating just part of the job — or doing all of it semi-automatically.
This month, let’s look at one way to do a job like this: with a set of handwritten macros for a text editor. (A macro lets you type a key or two to perform one or more editing steps in a flash.) We’ll use vi, because your columnist’s fingers are well-trained for it, but another programmable editor, like Emacs, should be at least as good. The important thing here is the way to design and use these macros, not which editor you choose.
Let’s look at a specific example: a small part of a job to convert a web site coded in HTML (the busy Google Guide site,