Forked from Jose E. Marchesi: http://www.jemarch.net/bugz-mode.html