Improve filename → identifier conversion in snippets

Also use document’s display name (relevant for untitled documents).