Literate Programming Examples from my Website


I have become rather interested in literate programming, which I find a very interesting and elegant approach. Literate programming was first proposed by Donald Knuth and it is supported very well by Emacs: consult the Org Mode manual for more information.

This page lists the pages of this website which use literate programming.

The first version has a list compiled by hand… I then realized I could be more efficient and precise by using code to extract the information and this page has become itself an example of literate programming.

First of all, we find all occurrences of #+BEGIN_SRC in the source files (with the exception of this file) which are required to produce results. We use sed to process the output, using a TAB to separate the filename from the content and by extracting the programming language, which is the first word after #+BEGIN_SRC.

grep BEGIN_SRC $(find ../.. -name "*.org" -a \! -name ) | grep results | grep -v "_site" | sed 's/:/\t/' | sed -E 's/#\+BEGIN_SRC +([^ ]+) .*/\1/' 

The output, which is not exported, looks like:

| ../../                                    | ruby    |
| ../../notes/covid/                         | R       |
| ../../notes/covid/                         | ruby    |

We now use datamash to make the data into a Pivot table, with the crosstab command. Sed is used to generate links to the files, by prepending file: to the filenames and to remove the “N/A” entries.

echo "$table" | sort | datamash crosstab 1,2 | sed 's-N/A--'g | sed -E 's/\.\./file:../' 
  R emacs-lisp gnuplot ruby shell
../../books/bookstats.html     4 4  
../../books/bookstream.html       1  
../../homepage-through-time.html       1  
../../notes/admin/inf-ruby-in-emacs-tips-and-tricks.html       1  
../../notes/admin/make-bootable-usb-stick.html         1
../../notes/categories.html       1  
../../notes/chronological.html       1  
../../notes/covid/covid.html 11        
../../notes/covid/index.html 1        
../../notes/covid/new-cases.html 4     1 1
../../notes/covid/tests.html 13        
../../notes/data-analysis/r-shifting-and-diffing-columns.html 6        
../../notes/emacs/gnuplot-histogram.html     4    
../../notes/emacsconf-2020/talk-reveal.html       1  
../../notes/emacsconf-2020/talk.html       1  
../../publications.html       1  
../../tutoring.html       1  
../../website-specification/generate-atom.html       1  
../../website-specification/generate-xml-sitemap.html       1  
../../website-specification/project-specification.html   8     1