It’s the little things.

April 1, 2008

The Usenet, once the dominant form of internet communication, has been rendered largely irrelevant by the World Wide Web. Yet, it can still be a great source of information: some technical groups (such as comp.lang.fortran) have an impressively high signal to noise ratio.

It was a search for esoteric Emacs knowledge that sent me to Emacs has a nice syntax highlighting ability which makes source code more readable, by associating color with functionality. I wanted intrinsic procedures such as “mod” or “exp” to highlight in a different color than executable constructs such as “if … then” statements. Fortran mode in Emacs does this by default, but F90 mode does not. Here’s an example:

Fortran mode

if (mod(k,10).eq.0) then
things to do

F90 mode

if (mod(k,10).eq.0) then
things to do

It’s a small difference, but in complicated code with many different procedures or constructs, it makes life much easier on my eyes. It wasn’t clear from the Emacs source how to make F90 mode match Fortran mode.

Luckily, Glenn Morris, the maintainer of the fortran.el and f90.el filters, reads and was able to give me a fix:

I don’t really know why it is like it is, but it is. Anyway, add to~/.emacs:

(eval-after-load "f90"
     (setq f90-font-lock-keywords-3
      (append f90-font-lock-keywords-2
           (list f90-procedures-re '(1 font-lock-builtin-face keep))
      f90-font-lock-keywords-4 (append f90-font-lock-keywords-3
          (list f90-hpf-keywords-re)))))

It works — my Fortran 90 looks good again. So many parentheses! The recently deceased Arthur C. Clarke may have imagined that most people would categorize Emacs Lisp scripting as magic.