The successful construction of all machinery depends on the perfection of the tools employed; and whoever is a master in the arts of tool-making possesses the key to the construction of all machines... The contrivance and construction of tools must therefore ever stand at the head of the industrial arts. (Charles Babbage)
People who have a necessity to publish source code for public view like
myself and Tony will benefit by this article.
It is rather funny since I have published a lot of code in this very
site without syntax highlighting. Perhaps things will change with this
Let me quickly cut to the chase. This article comes close on the heels
of my Vim article
and you shall see in a moment why.
Both my tips involve Vim and its genius is doing a perfect job of this.
Let us see for ourselves. We are going to use a C file sqlite2.c for
$ vim sqlite2.c
:hardcopy > %.ps
gets us the file sqlite2.c.ps which is a postscript file. If you open it
with gv you find that it is neatly syntax highlighted. This will only
happen if you have it enabled in your vimrc like this:
se spell spelllang=en_us
noremap :se nospell
Now that is an interesting vimrc. But let us focus on the first line
alone and get on with the article. The other way to do it is by opening
the file in vim and then highlighting the syntax manually with the
colon command ":sy on".
But we are not very happy with this for two reasons. It is in ps format
which is fine for academic papers and not for Internet publishing. And
the second problem with it is that it not suitable for batch
conversions. Hackers are incredibly lazy individuals who want the
computer to work for them. They don't want to sit and do the job.
What is the way out?
It turns out that there are two ways. One way is interesting. The other
a bit boring but both work well.
$ vim -me -e -c ":hardcopy >%.ps" -c ":q" sqlite2.c