Literate Programming Examples from my Website

Menu

I love 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.

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 literate-programming-references.org ) | \
    grep results | grep -v "_site" | sed 's/:/\t/' | \
    sed -E 's/#\+BEGIN_SRC +([^ ]+) .*/\1/' 

The output, which is not exported in the HTML page, looks like:

| ../../bookstream.org                                    | ruby    |
| ../../notes/covid/new-cases.org                         | R       |
| ../../notes/covid/new-cases.org                         | 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/index.html 1        
../../notes/covid/new-cases.html 4     1 1
../../notes/covid/overall-situation-in-italy.html 11        
../../notes/covid/tests.html 13        
../../notes/data-analysis/r-shifting-and-diffing-columns.html 6        
../../notes/emacs/emacs-initialization-file.html   1      
../../notes/emacs/gnuplot-histogram.html     4    
../../notes/emacsconf-2020/talk-reveal.html       1  
../../notes/emacsconf-2020/talk.html       1  
../../notes/emacsconf-2021/offer-en.html   1      
../../project-specification/project-specification.html   9     1
../../publications.html       1  
../../tutoring.html       1