fix Emacs crashing bug when rectangle ends at EOB

This supercedes the pull-request fixing #31