Some word phrases should be hyphenated. For example, you should write “an end-to-end solution” rather than “end to end solution.”1 If you’re like me, you almost always forget about the hyphenation initially and just type “end to end” without stopping to think about the hyphenation. It’s really a pain to have to go back and add them manually. Sometimes it’s easier to just delete the phrase and retype it correctly.
I’ve done this often enough that I realized it was time to automate hyphenating the phrase after the fact. I wrote a bit of Elisp but it seemed a little too complicated so I simplified things and came up with this:
(defun jcs-dashify () "Place hyphens between words in region." (interactive) (unless (use-region-p) (error "No region specified")) (replace-regexp "[ \n]+" "-" nil (region-beginning) (region-end)))
Now all I have to do is select the phrase and call
jcs-dashify. As with most extensions like this,
jcs-dashify is simple but helps reduce friction in my work flow. I’m sure you can do this sort of thing with most (decent) editors but Emacs makes it simple and natural. As Magnar Sveen says, one of the great about Emacs is its extensibility.