Perform substitution only when the document is dirty, so that it's consistent with the behavior of "Save All"