Now don’t get me wrong: I have nothing personal against those strange people who end their sentences with a single space, I just want them locked in some place so they don’t interfere with us normals. But reality is reality, and after I found that I'm not the only one being angry with the one-spacers sending me their crippled files, I decided to do something about it. This is really a ten minute hack and a proof of concept rather than a full solution, but what about this?
(defvar sentence-end-double-space-threshold 2 "How many occurrences of \". \" per kilobyte should be enough to declare this file as using two spaces after sentences.") (defun set-sentence-end-double-space () "Set `sentence-end-double-space' according to how often the literal string \". \" occurs in the current buffer." (make-local-variable 'sentence-end-double-space) (if (>= (* (count-matches "\\. ") 1024) (* (buffer-size) sentence-end-double-space-threshold)) (setq sentence-end-double-space t) (setq sentence-end-double-space nil))) (add-hook 'find-file-hook 'set-sentence-end-double-space)
Now when you open a file, Emacs decides (using the very conservative value of sentence-end-double-space-threshold
, which you can setq
to whatever you feel right) which style it is. (Obviously, this does not help in case of pasting from the browser or whatever. It could be done, advising yank
and – if needed – replacing spaces in the yanked text as necessary, but hey, I only had 15 minutes for that!)