Print comma before rather than after comments. Also switch to multiline mode if inserting an item with comments. Fixes #804.