Always autoreplace space before dash with non-breaking space?

Is there any option to make autocorrect work not only with anything between spaces? I want to always have a non-breaking space before a dash without the need to use Find and Replace on every document. Is it possible?

Take care: a non-breaking space is also a fixed width space, so in justified text these spaces may be narrower than normal spaces on the same line.

I’ve written a macro for that:

Sub nbsp_dash

Dim replace As Object

replace = ThisComponent.createReplaceDescriptor
replace.SearchString = " —"
replace.ReplaceString = " —"
ThisComponent.replaceAll(replace)

End Sub

20 points required to accept or unaccept your own answer