Fixing Two Spaces Between Sentences

Marcin Borkowski (mbork) has an interesting post on how to deal with two spaces after a sentence when transferring data from Emacs to an external application via the clipboard. The problem is that mbork likes to use two spaces so that he can take advantage of Emacs’ sentence-aware commands but most people—at least most Poles—insist, some strongly, on single spaces.

The one/two spaces between sentences is a long-standing holy war that I’ve written about before. Years after learning to put two spaces after sentences (an artifact of learning to type on an actual typewriter) I became persuaded that the one-spacers had the better story and converted to a single space. That, of course, broke the sentence-aware commands in Emacs but I didn’t mind too much. Then I discovered that, as usual, Emacs lets you have it your way. All you need do is tell Emacs how you end sentences:

(setq sentence-end-double-space nil) ;period single space ends sentence

For one reason or another, mbork chose not to use that solution and instead wrote some code to change the two spaces into one. His final solution will still have problems with code in some languages but appears to be working for him.

As well as being interesting, mbork’s post is also serendipitous. Serendipitous because his code for the changing the number of spaces echoes a point from Thursday’s post. Part of his code wants to move to the beginning of a buffer. He does that with (goto-char 0), which is incorrect because the lowest point in a buffer is 1 not 0. Nevertheless the code works. That’s for the same reason that (goto-char 1) works in a narrowed buffer: goto-char clips values outside buffer to be inside the buffer. Another example of Emacs having our backs.

Finally, mbork wonders if his strategy of using a buffer to make his transformations really makes much difference. The answer is almost certainly yes as Chris Wellons explained and I wrote about here.

Update [2021-02-13 Sat 16:56]: Used actual Elisp in goto-char invocations.
Update 2 [2021-02-14 Sun 14:49]: Added link to mbork’s post.

This entry was posted in General and tagged . Bookmark the permalink.