Address review comments from PR #118

This fixes exception previews, so that inline display of a syntax error in Scratchpad works. It also moves the stringification code to a separate module, as suggested in PR #118. Don't be alarmed by the large number of commits, only the last two are unique in this PR. The rest are from PR #121 on which this one is based.

r? @captainbrosset